summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJunio C Hamano <junkio@cox.net>2005-07-23 02:08:47 (GMT)
committerLinus Torvalds <torvalds@g5.osdl.org>2005-07-23 03:34:16 (GMT)
commita38e727925bfad369fc98165f6ff161193397f28 (patch)
treeb24f30818110c5370d58add1200601969fca88cb
parent5bb2c65aba9161ee77c42002009634e757005b4f (diff)
downloadgit-a38e727925bfad369fc98165f6ff161193397f28.zip
git-a38e727925bfad369fc98165f6ff161193397f28.tar.gz
git-a38e727925bfad369fc98165f6ff161193397f28.tar.bz2
[PATCH] git-branch: avoid getting confused by empty or nonexisting branches.
When not specifying the start point explicitly, we ended up emitting ^0 in addition to the default HEAD. Be careful to see if we have "$2" before finding out which commit to base the new branch on. Signed-off-by: Junio C Hamano <junkio@cox.net> Signed-off-by: Junio C Hamano <junkio@cox.net>
-rwxr-xr-xgit-branch-script8
1 files changed, 7 insertions, 1 deletions
diff --git a/git-branch-script b/git-branch-script
index ade0abf..041ca51 100755
--- a/git-branch-script
+++ b/git-branch-script
@@ -3,7 +3,13 @@
. git-sh-setup-script || die "Not a git archive"
branchname="$1"
-rev=$(git-rev-parse --verify --default HEAD "$2"^0) || exit
+case "$2" in
+'')
+ head=HEAD ;;
+*)
+ head="$2^0" ;;
+esac
+rev=$(git-rev-parse --revs-only --verify "$head") || exit
[ -z "$branchname" ] && die "git branch: I want a branch name"
[ -e "$GIT_DIR/refs/heads/$branchname" ] && die "$branchname already exists"