Teach "git checkout" to use git-show-ref

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



That way, it doesn't care how the refs are stored any more

Signed-off-by: Linus Torvalds <torvalds@xxxxxxxx>
---

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.

diff --git a/git-checkout.sh b/git-checkout.sh
index 580a9e8..6e4c535 100755
--- a/git-checkout.sh
+++ b/git-checkout.sh
@@ -22,7 +22,7 @@ while [ "$#" != "0" ]; do
 		shift
 		[ -z "$newbranch" ] &&
 			die "git checkout: -b needs a branch name"
-		[ -e "$GIT_DIR/refs/heads/$newbranch" ] &&
+		git-show-ref --verify --quiet -- "refs/heads/$newbranch" &&
 			die "git checkout: branch $newbranch already exists"
 		git-check-ref-format "heads/$newbranch" ||
 			die "git checkout: we do not like '$newbranch' as a branch name."
@@ -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)
-
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]