rebase: consistently use branch_name variable
[gitweb.git] / git-rebase.sh
index 60b70f3defb5678af099e4c6bd7fe0610035a432..a299bcc52029bb1cdcefb5d985b186df8fe8c242 100755 (executable)
@@ -518,7 +518,7 @@ case "$onto_name" in
 esac
 
 # If the branch to rebase is given, that is the branch we will rebase
-# $branch_name -- branch being rebased, or HEAD (already detached)
+# $branch_name -- branch/commit being rebased, or HEAD (already detached)
 # $orig_head -- commit object name of tip of the branch before rebasing
 # $head_name -- refs/heads/<that-branch> or "detached HEAD"
 switch_to=
@@ -528,15 +528,18 @@ case "$#" in
        branch_name="$1"
        switch_to="$1"
 
-       if git show-ref --verify --quiet -- "refs/heads/$1" &&
-          orig_head=$(git rev-parse -q --verify "refs/heads/$1")
+       # Is it a local branch?
+       if git show-ref --verify --quiet -- "refs/heads/$branch_name" &&
+          orig_head=$(git rev-parse -q --verify "refs/heads/$branch_name")
        then
-               head_name="refs/heads/$1"
-       elif orig_head=$(git rev-parse -q --verify "$1")
+               head_name="refs/heads/$branch_name"
+       # If not is it a valid ref (branch or commit)?
+       elif orig_head=$(git rev-parse -q --verify "$branch_name")
        then
                head_name="detached HEAD"
+
        else
-               die "$(eval_gettext "fatal: no such branch: \$branch_name")"
+               die "$(eval_gettext "fatal: no such branch/commit: \$branch_name")"
        fi
        ;;
 0)
@@ -547,7 +550,7 @@ case "$#" in
                branch_name=$(expr "z$branch_name" : 'zrefs/heads/\(.*\)')
        else
                head_name="detached HEAD"
-               branch_name=HEAD ;# detached
+               branch_name=HEAD
        fi
        orig_head=$(git rev-parse --verify HEAD) || exit
        ;;