Commits

Anonymous committed 13d1cc3

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>

  • Participants
  • Parent commits 4ccafd7

Comments (0)

Files changed (2)

File git-branch.sh

 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"

File git-checkout.sh

 #
 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" ] &&