Re: Teach "git checkout" to use git-show-ref
- From
Junio C Hamano <junkio@cox.net>
- Date
- Sep 16, 2006, 09:33 UTC
- Message-ID
- <7vpsdw9mvg.fsf@assigned-by-dhcp.cox.net>
- In-Reply-To
- <Pine.LNX.4.64.0609151455150.4388@g5.osdl.org>
Linus Torvalds <torvalds@osdl.org> writes:
Show 11 quoted lines
> That way, it doesn't care how the refs are stored any more > > Signed-off-by: Linus Torvalds <torvalds@osdl.org> > --- > > Just as an example of how to use git-show-ref rather than knowing about > "$GIT_DIR/refs/..." paths. > > This basically replaces my much hackier version that is in the "lt/refs" > branch, but can go into the master branch independently of the > refs-packing work.
I kind of liked the rev-parse one better for this particular command, but only slightly (by using --verify on "$arg^0", you were also making sure what's in refs/heads/ was a commit object, but that check is gone with this patch. It is not a loss, because the original code did not check it, and nobody should be placing anything but commits under refs/heads anyway).
Show 14 quoted lines
> diff --git a/git-checkout.sh b/git-checkout.sh
> index 580a9e8..6e4c535 100755
> --- a/git-checkout.sh
> +++ b/git-checkout.sh
>...
> @@ -51,7 +51,7 @@ while [ "$#" != "0" ]; do
> fi
> new="$rev"
> new_name="$arg^0"
> - if [ -f "$GIT_DIR/refs/heads/$arg" ]; then
> + if git-show-ref --verify --quiet -- "refs/heads/$arg" ]; then
> branch="$arg"
> fi
> elif rev=$(git-rev-parse --verify "$arg^{tree}" 2>/dev/null)