lock_ref_sha1(): do not sometimes error() and sometimes die().
[gitweb.git] / git-branch.sh
index 2600e9c4a81a0d3aa0d23bde23b6b0b34256b4d2..c61683033da84b6630aff7451f829040be9d5a37 100755 (executable)
@@ -42,8 +42,7 @@ If you are sure you want to delete it, run 'git branch -D $branch_name'."
            esac
            ;;
        esac
-       rm -f "$GIT_DIR/logs/refs/heads/$branch_name"
-       rm -f "$GIT_DIR/refs/heads/$branch_name"
+       git update-ref -d "refs/heads/$branch_name" "$branch"
        echo "Deleted branch $branch_name."
     done
     exit 0
@@ -112,6 +111,27 @@ rev=$(git-rev-parse --verify "$head") || exit
 git-check-ref-format "heads/$branchname" ||
        die "we do not like '$branchname' as a branch name."
 
+if [ -d "$GIT_DIR/refs/heads/$branchname" ]
+then
+       for refdir in `cd "$GIT_DIR" && \
+               find "refs/heads/$branchname" -type d | sort -r`
+       do
+               rmdir "$GIT_DIR/$refdir" || \
+                   die "Could not delete '$refdir', there may still be a ref there."
+       done
+fi
+
+branchdir=$(dirname $branchname)
+while test "$branchdir" != "."
+do
+       if git-show-ref --verify --quiet -- "refs/heads/$branchdir"
+       then
+               die "$branchdir already exists."
+       fi
+       branchdir=$(dirname $branchdir)
+done
+
+prev=''
 if git-show-ref --verify --quiet -- "refs/heads/$branchname"
 then
        if test '' = "$force"
@@ -121,10 +141,11 @@ then
        then
                die "cannot force-update the current branch."
        fi
+       prev=`git rev-parse --verify "refs/heads/$branchname"`
 fi
 if test "$create_log" = 'yes'
 then
        mkdir -p $(dirname "$GIT_DIR/logs/refs/heads/$branchname")
        touch "$GIT_DIR/logs/refs/heads/$branchname"
 fi
-git update-ref -m "branch: Created from $head" "refs/heads/$branchname" $rev
+git update-ref -m "branch: Created from $head" "refs/heads/$branchname" "$rev" "$prev"