cmd/go: avoid misleading git fatal message in a repo with no commits - #81258
Open
harjothkhara wants to merge 1 commit into
Open
cmd/go: avoid misleading git fatal message in a repo with no commits#81258harjothkhara wants to merge 1 commit into
harjothkhara wants to merge 1 commit into
Conversation
In a git repository with no commits yet, the "git log" command that
stamps VCS information fails and prints
fatal: your current branch 'main' does not have any commits yet
to the user's console during builds with -v, even though the build
succeeds. If the repository is also clean (for example, all files are
ignored), the build instead fails with "error obtaining VCS status".
Pass --ignore-missing and name HEAD explicitly, so that git succeeds
with no output when there are no commits, and skip stamping the
revision and commit time in that case. The flag is supported since at
least Git 1.7.6. An empty repository now builds without the message,
stamping only vcs and vcs.modified.
CL 399828 by Filippo Rossi fixed this with "git rev-list -n 1 --all".
That walks all refs, so in a repository with more than one branch it
can report a commit other than the one checked out. Using
"log --ignore-missing HEAD" keeps the stamped revision the same as
today for repositories that have commits. The test is based on the one
in CL 399828, updated for the review comments there.
Fixes golang#52263
Contributor
|
This PR (HEAD: 1273393) has been imported to Gerrit for code review. Please visit Gerrit at https://go-review.googlesource.com/c/go/+/825284. Important tips:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In a git repository with no commits, "go build -v" prints git's
misleading message
and a repository with no commits and a clean status fails to build
with "error obtaining VCS status".
Pass --ignore-missing and name HEAD explicitly so that git succeeds
with no output when there are no commits, and skip stamping the
revision and commit time in that case.
The abandoned CL 399828 by Filippo Rossi fixed this with
"git rev-list -n 1 --all", which can report a commit other than the
one checked out when the repository has more than one branch.
"log --ignore-missing HEAD" keeps the stamped revision unchanged for
repositories with commits.
Fixes #52263