Skip to content

Commit

Permalink
Do not fail on hierarchical branch names.
Browse files Browse the repository at this point in the history
"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>
  • Loading branch information
Junio C Hamano committed Nov 3, 2005
1 parent 4ccafd7 commit 13d1cc3
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 2 additions & 0 deletions git-branch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
4 changes: 3 additions & 1 deletion git-checkout.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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" ] &&
Expand Down

0 comments on commit 13d1cc3

Please sign in to comment.