}
appendSetting("vcs.modified", strconv.FormatBool(st.Uncommitted))
// Determine the correct version of this module at the current revision and update the build metadata accordingly.
- repo := modfetch.LookupLocal(ctx, p.Module.Dir)
+ repo := modfetch.LookupLocal(ctx, repoDir)
revInfo, err := repo.Stat(ctx, st.Revision)
if err != nil {
goto omitVCS
remote string
cmd *vcsCmd
dir string
+ local bool
tagsOnce sync.Once
tags map[string]bool
if vcs == "git" {
return newGitRepo(ctx, remote, local)
}
+ r := &vcsRepo{remote: remote, local: local}
cmd := vcsCmds[vcs]
if cmd == nil {
return nil, fmt.Errorf("unknown vcs: %s %s", vcs, remote)
}
+ r.cmd = cmd
+ if local {
+ info, err := os.Stat(remote)
+ if err != nil {
+ return nil, err
+ }
+ if !info.IsDir() {
+ return nil, fmt.Errorf("%s exists but is not a directory", remote)
+ }
+ r.dir = remote
+ r.mu.Path = r.dir + ".lock"
+ return r, nil
+ }
if !strings.Contains(remote, "://") {
return nil, fmt.Errorf("invalid vcs remote: %s %s", vcs, remote)
}
-
- r := &vcsRepo{remote: remote, cmd: cmd}
var err error
r.dir, r.mu.Path, err = WorkDir(ctx, vcsWorkDirType+vcs, r.remote)
if err != nil {
rev = r.cmd.latest
}
r.branchesOnce.Do(func() { r.loadBranches(ctx) })
+ if r.local {
+ // Ignore the badLocalRevRE precondition in local only mode.
+ // We cannot fetch latest upstream changes so only serve what's in the local cache.
+ return r.statLocal(ctx, rev)
+ }
revOK := (r.cmd.badLocalRevRE == nil || !r.cmd.badLocalRevRE.MatchString(rev)) && !r.branches[rev]
if revOK {
if info, err := r.statLocal(ctx, rev); err == nil {
go install
go version -m $GOBIN/a$GOEXE
! stdout hgrevision
+stdout '\s+mod\s+example.com/a\s+\(devel\)'
rm $GOBIN/a$GOEXE
# If there is a repository, but it can't be used for some reason,
stdout '^\tbuild\tvcs.revision=0000000000000000000000000000000000000000$'
stdout '^\tbuild\tvcs.time=1970-01-01T00:00:00Z$'
stdout '^\tbuild\tvcs.modified=true$'
+stdout '\s+mod\s+example.com/a\s+v0.0.0-19700101000000-000000000000\+dirty'
cd ..
# Revision and commit time are tagged for repositories with commits.
exec hg add a README
exec hg commit -m 'initial commit' --user test-user --date '2024-07-31T01:21:27+00:00'
+exec hg tag v1.2.3
+# Switch back to the tagged branch.
+# Tagging a commit causes a new commit to be created. (See https://repo.mercurial-scm.org/hg/help/revsets)
+exec hg update '.~1'
cd a
go install
go version -m $GOBIN/a$GOEXE
stdout '^\tbuild\tvcs.revision=71eaed52daeaafea83cb604f75b0a0336ef2c345$'
stdout '^\tbuild\tvcs.time=2024-07-31T01:21:27Z$'
stdout '^\tbuild\tvcs.modified=false$'
+stdout '\s+mod\s+example.com/a\s+v1.2.3\s+'
rm $GOBIN/a$GOEXE
# Add an extra commit and then back off of it to show that the hash is
stdout '^\tbuild\tvcs.revision=71eaed52daeaafea83cb604f75b0a0336ef2c345$'
stdout '^\tbuild\tvcs.time=2024-07-31T01:21:27Z$'
stdout '^\tbuild\tvcs.modified=false$'
+stdout '\s+mod\s+example.com/a\s+v1.2.3\s+'
rm $GOBIN/a$GOEXE
# Building with -buildvcs=false suppresses the info.
go install -buildvcs=false
go version -m $GOBIN/a$GOEXE
! stdout hgrevision
+stdout '\s+mod\s+example.com/a\s+\(devel\)'
rm $GOBIN/a$GOEXE
# An untracked file is shown as uncommitted, even if it isn't part of the build.
go install
go version -m $GOBIN/a$GOEXE
stdout '^\tbuild\tvcs.modified=true$'
+stdout '\s+mod\s+example.com/a\s+v1.2.3\+dirty\s+'
rm empty.txt
rm $GOBIN/a$GOEXE
go install
go version -m $GOBIN/a$GOEXE
stdout '^\tbuild\tvcs.modified=true$'
+stdout '\s+mod\s+example.com/a\s+v1.2.3\+dirty\s+'
exec hg revert ../README
rm $GOBIN/a$GOEXE