From 3a9156adc774f28b3b0f880cdd285a7e01118d15 Mon Sep 17 00:00:00 2001 From: Kaartic Sivaraam Date: Sat, 16 Dec 2017 14:33:17 +0530 Subject: [PATCH] rebase: consistently use branch_name variable The variable "branch_name" holds the parameter in "git rebase ", but one codepath did not use it after assigning $1 to it (instead it kept using $1). Make it use the variable consistently. Also, update an error message to say there is no such branch or commit, as we are expecting either of them, and not limiting ourselves to a branch name. Signed-off-by: Kaartic Sivaraam Signed-off-by: Junio C Hamano Signed-off-by: Kaartic Sivaraam Signed-off-by: Junio C Hamano --- git-rebase.sh | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/git-rebase.sh b/git-rebase.sh index 60b70f3def..a299bcc520 100755 --- a/git-rebase.sh +++ b/git-rebase.sh @@ -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/ 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 ;; -- 2.11.4.GIT