git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jeff King <peff@peff.net>
To: Sven Strickroth <sven.strickroth@tu-clausthal.de>
Cc: git@vger.kernel.org
Subject: Re: howto handle name clashes
Date: Fri, 23 Mar 2012 14:29:52 -0400	[thread overview]
Message-ID: <20120323182941.GA14236@sigill.intra.peff.net> (raw)
In-Reply-To: <4F6CB649.8080006@tu-clausthal.de>

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

  reply	other threads:[~2012-03-23 18:30 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-03-23 13:06 howto handle name clashes Sven Strickroth
2012-03-23 17:12 ` Jeff King
2012-03-23 17:43   ` Sven Strickroth
2012-03-23 18:29     ` Jeff King [this message]
2012-03-24  0:19   ` Sven Strickroth
2012-03-23 18:25 ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20120323182941.GA14236@sigill.intra.peff.net \
    --to=peff@peff.net \
    --cc=git@vger.kernel.org \
    --cc=sven.strickroth@tu-clausthal.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).