From: Alex Riesen <raa.lkml@gmail.com>
To: Git Mailing List <git@vger.kernel.org>
Cc: Brandon Casey <casey@nrlssc.navy.mil>, Junio C Hamano <junkio@cox.net>
Subject: Re: git does the wrong thing with ambiguous names
Date: Thu, 7 Jun 2007 02:01:00 +0200 [thread overview]
Message-ID: <20070607000100.GE3969@steel.home> (raw)
In-Reply-To: <20070606233327.GD3969@steel.home>
Alex Riesen, Thu, Jun 07, 2007 01:33:27 +0200:
> Alex Riesen, Thu, Jun 07, 2007 00:58:26 +0200:
> > Brandon Casey, Thu, Jun 07, 2007 00:13:48 +0200:
> > >
> > > When a branch and tag have the same name, a git-checkout using that name
> > > succeeds (exits zero without complaining), switches to the _branch_, but
> > > updates the working directory contents to that specified by the _tag_.
> > > git-status show modified files.
> >
> > Bad. To reproduce:
> >
> > mkdir a && cd a && git init && :> a && git add . && git commit -m1 &&
> > :>b && git add . && git commit -m2 && git tag master HEAD^ &&
> > find .git/refs/ && gco -b new && gco master && git status
> >
>
> git-rev-parse actually warns about ambguities:
>
> $ git-rev-parse --verify master
> warning: refname 'master' is ambiguous.
> dd5cdc387f2160bf04d02ac08dfdaf952f769357
>
> It's just that the warning is thrown away in git-checkout.sh
>
> A quick and _very_ messy fix could like like that:
>
This one is much shorter and less friendly. Suggested by Junio on irc.
It makes checkout always prefer a branch.
diff --git a/git-checkout.sh b/git-checkout.sh
index 6b6facf..282c84f 100755
--- a/git-checkout.sh
+++ b/git-checkout.sh
@@ -67,6 +67,8 @@ while [ "$#" != "0" ]; do
new_name="$arg"
if git-show-ref --verify --quiet -- "refs/heads/$arg"
then
+ rev=$(git-rev-parse --verify "refs/heads/$arg^0" 2>/dev/null)
+ new="$rev"
branch="$arg"
fi
elif rev=$(git-rev-parse --verify "$arg^{tree}" 2>/dev/null)
next prev parent reply other threads:[~2007-06-07 0:01 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-06-06 22:13 git does the wrong thing with ambiguous names Brandon Casey
2007-06-06 22:58 ` Alex Riesen
2007-06-06 23:33 ` Alex Riesen
2007-06-07 0:01 ` Alex Riesen [this message]
2007-06-07 14:41 ` Brandon Casey
2007-06-07 14:54 ` Brandon Casey
-- strict thread matches above, loose matches on Subject: below --
2007-06-07 22:51 Brandon Casey
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=20070607000100.GE3969@steel.home \
--to=raa.lkml@gmail.com \
--cc=casey@nrlssc.navy.mil \
--cc=git@vger.kernel.org \
--cc=junkio@cox.net \
/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).