From: Junio C Hamano Date: Wed, 2 Nov 2005 20:17:47 +0000 (-0800) Subject: Do not fail on hierarchical branch names. X-Git-Tag: v0.99.9c^2~11 X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=13d1cc3604a1a64cb5a6025bba8af8b74a373963;p=git.git 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 --- diff --git a/git-branch.sh b/git-branch.sh index e2db9063..67f113ac 100755 --- a/git-branch.sh +++ b/git-branch.sh @@ -102,4 +102,6 @@ rev=$(git-rev-parse --verify "$head") || exit git-check-ref-format "heads/$branchname" || die "we do not like '$branchname' as a branch name." +leading=`expr "refs/heads/$branchname" : '\(.*\)/'` && +mkdir -p "$GIT_DIR/$leading" && echo $rev > "$GIT_DIR/refs/heads/$branchname" diff --git a/git-checkout.sh b/git-checkout.sh index cb33fdc7..4c08f36b 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" ] &&