@matheusbsbs / matheus-bagliano / commits / 13d1cc3604
Fork 0

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 <junkio@cox.net>

Junio C Hamano committed Nov 2, 2005 at 12:17 UTC 13d1cc3604a1a64cb5a6025bba8af8b74a373963
2 files changed +5 -1
git-branch.sh
+2
@@ -102,4 +102,6 @@ rev=$(git-rev-parse --verify "$head") || exit
102 git-check-ref-format "heads/$branchname" ||
103 die "we do not like '$branchname' as a branch name."
104
105 +leading=`expr "refs/heads/$branchname" : '\(.*\)/'` &&
106 +mkdir -p "$GIT_DIR/$leading" &&
107 echo $rev > "$GIT_DIR/refs/heads/$branchname"
git-checkout.sh
+3 -1
@@ -126,7 +126,9 @@ fi
126 #
127 if [ "$?" -eq 0 ]; then
128 if [ "$newbranch" ]; then
129 - echo $new > "$GIT_DIR/refs/heads/$newbranch"
129 + leading=`expr "refs/heads/$newbranch" : '\(.*\)/'` &&
130 + mkdir -p "$GIT_DIR/$leading" &&
131 + echo $new >"$GIT_DIR/refs/heads/$newbranch" || exit
132 branch="$newbranch"
133 fi
134 [ "$branch" ] &&