howto handle name clashes
Hi,
how to handle name clashes for branches and tags? Is there anything I can add to the refspec to make the name unique?
E.g.
- for merging "git merge --no-ff refs/branches/test" works, but generates a not so nice default merge message. ("merged commit refs/branches/test" instead of "merged branch test")
- how to drop a remote tag/branch ("git push origin :test" does not work)
Signature · 4 lines
Best regards, Sven Strickroth ClamAV, a GPL anti-virus toolkit http://www.clamav.net PGP key id F5A9D4C4 @ any key-server
Quoted 2 lines · Sven Strickroth
how to handle name clashes for branches and tags? Is there anything I can add to the refspec to make the name unique?
You can always use a more fully-qualified name to disambiguate (e.g., "tags/foo", or "refs/tags/foo").
Quoted 3 lines
- for merging "git merge --no-ff refs/branches/test" works, but generates a not so nice default merge message. ("merged commit refs/branches/test" instead of "merged branch test")
Did you mean "refs/heads/test"?
I would have thought we would full-qualify the refname first, and then use that to determine the message. Doing a simple test, it looks like "git merge foo" gets you "Merge branch 'foo'", but "git merge heads/foo" will get you "Merge branch 'heads/foo'". We should be able to do better in the latter case.
Quoted 1 line
- how to drop a remote tag/branch ("git push origin :test" does not work)
Does "git push origin :heads/foo" (or :tags/foo) not work?
-Peff
Am 23.03.2012 18:12 schrieb Jeff King:
Quoted 5 lines
Quoted 3 lines
- for merging "git merge --no-ff refs/branches/test" works, but generates a not so nice default merge message. ("merged commit refs/branches/test" instead of "merged branch test")
Did you mean "refs/heads/test"?
yes. Your example was the correct one. Thanks for spotting my problem.
Quoted 3 lines
Quoted 1 line
- how to drop a remote tag/branch ("git push origin :test" does not work)
Does "git push origin :heads/foo" (or :tags/foo) not work?
seems to work. Thanks.
Really problematic is checkout:
"git checkout heads/foo" creates a detached HEAD (is this intended). However, "git checkout heads/foo -B foo" can be used.
Is there a git command to find out if a name is ambiguous? "git rev-parse foo" outputs "warning: refname 'test' is ambiguous.", but the return code is zero.
Signature · 4 lines
Best regards, Sven Strickroth ClamAV, a GPL anti-virus toolkit http://www.clamav.net PGP key id F5A9D4C4 @ any key-server
Quoted 3 lines · Sven Strickroth
Really problematic is checkout:
"git checkout heads/foo" creates a detached HEAD (is this intended). However, "git checkout heads/foo -B foo" can be used.
Checkout is unlike regular ref lookup in that it prefers branches to other forms (because it is fundamentally a branch operation). So "git checkout foo" should always choose "refs/heads/foo". We do still seem to give the ambiguity warning, though, which seems like overkill.
I think that generally people would want to get rid of ambiguous refs as soon as they notice them, as they are a recipe for disaster. So the warning being annoying has not been considered a huge problem.
Quoted 3 lines
Is there a git command to find out if a name is ambiguous? "git rev-parse foo" outputs "warning: refname 'test' is ambiguous.", but the return code is zero.
I think you could do:
case "$(git show-ref --tags --heads $name | wc -l)" in
0) echo "$name does not exist" ;;
1) echo "$name is unambiguous" ;;
*) echo "$name is ambiguous" ;;
esac
You could also get a list of all ambiguous refs like this:
git for-each-ref --format='%(refname:short)' refs/heads refs/tags | egrep '^(heads|tags)'
The ":short" modifier will shorten names unambiguously, so it ends up leaving the "heads" and "tags" in for ambiguous names.
-Peff
Am 23.03.2012 18:12 schrieb Jeff King:
Quoted 4 lines
Quoted 2 lines
- how to drop a remote tag/branch ("git push origin :test" does not work)
Does "git push origin :heads/foo" (or :tags/foo) not work?
well, ":heads/foo" does not work. Imagine I want to drop a remote branch which is ambiguous (e.g. a tag with same name exists) on the repository:
"git push origin :food"
gives me: "error: dst refspec food matches more than one."
However, deleting the remote tag (:tags/foo) works with your suggestion.
"git push origin :refs/remotes/origin/foo" showed success (and warning "remote: warning: Allowing deletion of corrupt ref."), but did not work.
Signature · 4 lines
Best regards, Sven Strickroth ClamAV, a GPL anti-virus toolkit http://www.clamav.net PGP key id F5A9D4C4 @ any key-server
Quoted 7 lines · Sven Strickroth
how to handle name clashes for branches and tags? Is there anything I can add to the refspec to make the name unique?
E.g.
- for merging "git merge --no-ff refs/branches/test" works, but generates a not so nice default merge message. ("merged commit refs/branches/test" instead of "merged branch test")
That's the price you pay for naming different things the same and having to disambiguate it.
Quoted 1 line
- how to drop a remote tag/branch ("git push origin :test" does not work)
"git push origin :refs/tags/test"
It is sad that some people teach new people shorthand without telling them that what they are teaching are merely shorthand and cause confusion like this.