threads / discuss / 30035

howto handle name clashes

Subject: howto handle name clashes

## tl;dr

6 messages between Mar 23, 2012 and Mar 24, 2012.

replies: 5people: 3as markdown or json

Sven Strickroth· Mar 23, 2012, 13:06 UTC · lore
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)
-- 
Best regards,
 Sven Strickroth
 ClamAV, a GPL anti-virus toolkit   http://www.clamav.net
 PGP key id F5A9D4C4 @ any key-server
Jeff King· Mar 23, 2012, 17:12 UTC · re: Sven Strickroth · lore

Re: howto handle name clashes

On Fri, Mar 23, 2012 at 02:06:01PM +0100, Sven Strickroth wrote:
> 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").

> - 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.

> - 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
Sven Strickroth· Mar 23, 2012, 17:43 UTC · re: Jeff King · lore

Re: howto handle name clashes

Am 23.03.2012 18:12 schrieb Jeff King:
Show 5 quoted 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.
>> - 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.

-- 
Best regards,
 Sven Strickroth
 ClamAV, a GPL anti-virus toolkit   http://www.clamav.net
 PGP key id F5A9D4C4 @ any key-server
Jeff King· Mar 23, 2012, 18:29 UTC · re: Sven Strickroth · lore

Re: howto handle name clashes

On Fri, Mar 23, 2012 at 06:43:37PM +0100, Sven Strickroth wrote:
> 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.

> 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
Sven Strickroth· Mar 24, 2012, 00:19 UTC · re: Jeff King · lore

Re: howto handle name clashes

Am 23.03.2012 18:12 schrieb Jeff King:
>> - 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.

-- 
Best regards,
 Sven Strickroth
 ClamAV, a GPL anti-virus toolkit   http://www.clamav.net
 PGP key id F5A9D4C4 @ any key-server
Junio C Hamano· Mar 23, 2012, 18:25 UTC · re: Sven Strickroth · lore

Re: howto handle name clashes

Sven Strickroth <sven.strickroth@tu-clausthal.de> writes:
Show 7 quoted lines
> 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.

> - 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.

← back to recent threads