From 3a9156adc774f28b3b0f880cdd285a7e01118d15 Mon Sep 17 00:00:00 2001 From: Kaartic Sivaraam Date: Sat, 16 Dec 2017 14:33:17 +0530 Subject: [PATCH 1/3] 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 ;; From ca7de7b12a13c4531485788b07259a2e241f8159 Mon Sep 17 00:00:00 2001 From: Kaartic Sivaraam Date: Sat, 16 Dec 2017 14:33:18 +0530 Subject: [PATCH 2/3] rebase: distinguish user input by quoting it 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 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/git-rebase.sh b/git-rebase.sh index a299bcc520..0f379ba2b5 100755 --- a/git-rebase.sh +++ b/git-rebase.sh @@ -477,7 +477,7 @@ then ;; esac upstream=$(peel_committish "${upstream_name}") || - die "$(eval_gettext "invalid upstream \$upstream_name")" + die "$(eval_gettext "invalid upstream '\$upstream_name'")" upstream_arg="$upstream_name" else if test -z "$onto" @@ -539,7 +539,7 @@ case "$#" in head_name="detached HEAD" else - die "$(eval_gettext "fatal: no such branch/commit: \$branch_name")" + die "$(eval_gettext "fatal: no such branch/commit '\$branch_name'")" fi ;; 0) From 08e66700dff55640d4698c081ab3732528563396 Mon Sep 17 00:00:00 2001 From: Kaartic Sivaraam Date: Sat, 16 Dec 2017 14:33:19 +0530 Subject: [PATCH 3/3] rebase: rebasing can also be done when HEAD is detached Attempting to rebase when the HEAD is detached and is already up to date with upstream (so there's nothing to do), the following message is shown Current branch HEAD is up to date. which is clearly wrong as HEAD is not a branch. Handle the special case of HEAD correctly to give a more precise error message. 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 | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/git-rebase.sh b/git-rebase.sh index 0f379ba2b5..fd72a35c65 100755 --- a/git-rebase.sh +++ b/git-rebase.sh @@ -601,11 +601,23 @@ then test -z "$switch_to" || GIT_REFLOG_ACTION="$GIT_REFLOG_ACTION: checkout $switch_to" \ git checkout -q "$switch_to" -- - say "$(eval_gettext "Current branch \$branch_name is up to date.")" + if test "$branch_name" = "HEAD" && + ! git symbolic-ref -q HEAD + then + say "$(eval_gettext "HEAD is up to date.")" + else + say "$(eval_gettext "Current branch \$branch_name is up to date.")" + fi finish_rebase exit 0 else - say "$(eval_gettext "Current branch \$branch_name is up to date, rebase forced.")" + if test "$branch_name" = "HEAD" && + ! git symbolic-ref -q HEAD + then + say "$(eval_gettext "HEAD is up to date, rebase forced.")" + else + say "$(eval_gettext "Current branch \$branch_name is up to date, rebase forced.")" + fi fi fi