From 13d1cc3604a1a64cb5a6025bba8af8b74a373963 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Wed, 2 Nov 2005 12:17:47 -0800 Subject: Do not fail on hierarchical branch names. "git-checkout -b frotz/nitfol master" failed to create $GIT_DIR/refs/heads/frotz/nitfol but went ahead and updated $GIT_DIR/HEAD to point at it, resulting in a corrupt repository. Exit when we cannot create the new branch with an error status. While we are at it, there is no reason to forbid subdirectories in refs/heads, so make sure we handle that correctly. Signed-off-by: Junio C Hamano --- git-checkout.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'git-checkout.sh') diff --git a/git-checkout.sh b/git-checkout.sh index cb33fdc7e2..4c08f36b59 100755 --- a/git-checkout.sh +++ b/git-checkout.sh @@ -126,7 +126,9 @@ fi # if [ "$?" -eq 0 ]; then if [ "$newbranch" ]; then - echo $new > "$GIT_DIR/refs/heads/$newbranch" + leading=`expr "refs/heads/$newbranch" : '\(.*\)/'` && + mkdir -p "$GIT_DIR/$leading" && + echo $new >"$GIT_DIR/refs/heads/$newbranch" || exit branch="$newbranch" fi [ "$branch" ] && -- cgit v1.2.3