Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix checkout when there is a file called HEAD in the repository root #1223

Merged
merged 1 commit into from
Aug 7, 2020

Conversation

zhenyavinogradov
Copy link
Contributor

Problem: git show HEAD fails when there is a file called 'HEAD' in the
repository root, complaining about ambiguous reference

Solution: call git show without 'HEAD' argument, which will always show
the HEAD commit

Copy link
Contributor

@chloeruka chloeruka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey! Thanks for your PR and for your work discovering the bug.

As a general practice, we like to lean on keeping things more verbose to make sure the intention is unambiguous to the reader rather than relying on default behaviour. @matthewd has done a little digging and it looks like appending double dashes at the end of the command e.g. git show HEAD -- would preserve this while also excluding files named 'HEAD' from matching the reference. If you can update this PR I'd consider it ready to merge.

Here's a brief example of how this would fix the issue:

❯ touch HEAD
❯ git --no-pager show HEAD -s --format=fuller --no-color
fatal: ambiguous argument 'HEAD': both revision and filename
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'
❯ git --no-pager show HEAD -s --format=fuller --no-color --
commit 31ee3e7c99fb06fd1e3412cd9b1c31476f601cce (HEAD -> master, origin/master, origin/HEAD)
Merge: 9861706c 4470cf59
Author:     Paul Annesley <[email protected]>
AuthorDate: Wed Jul 15 19:30:25 2020 +1000
Commit:     GitHub <[email protected]>
CommitDate: Wed Jul 15 19:30:25 2020 +1000

Problem: `git show HEAD` fails when there is a file called 'HEAD' in the
repository root, complaining about ambiguous reference

Solution: append '--' to `git show` arguments to indicate that 'HEAD'
must be interpreted as a revision
@zhenyavinogradov
Copy link
Contributor Author

Thanks for replying, I've updated it to use --

Copy link

@jayco jayco left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zhenyavinogradov looks good!

@jayco jayco requested a review from chloeruka August 4, 2020 08:17
Copy link
Member

@pda pda left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Huh, I've never seen -- used at the end of a command with nothing after it, but it kind of makes sense here 👍🏼

@jayco jayco dismissed chloeruka’s stale review August 7, 2020 03:31

This change has been made

@jayco jayco merged commit f6d8056 into buildkite:master Aug 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants