rebase: allow "-" short-hand for the previous branch

Teach rebase the same shorthand as checkout and merge to name the branch to rebase the current branch on; that is, that "-" means "the branch we were previously on". Requested-by: Tim Chase <git@tim.thechases.com> Signed-off-by: Brian Gesiak <modocache@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Brian Gesiak committed Mar 19, 2014 at 20:02 UTC 4f4074077fb0c3a2facc61b333337d024aeeebbf
2 files changed +21
git-rebase.sh
+4
@@ -449,6 +449,10 @@ then
449 test "$fork_point" = auto && fork_point=t
450 ;;
451 *) upstream_name="$1"
452 + if test "$upstream_name" = "-"
453 + then
454 + upstream_name="@{-1}"
455 + fi
456 shift
457 ;;
458 esac
t/t3400-rebase.sh
+17
@@ -88,6 +88,23 @@ test_expect_success 'rebase from ambiguous branch name' '
88 git rebase master
89 '
90
91 +test_expect_success 'rebase off of the previous branch using "-"' '
92 + git checkout master &&
93 + git checkout HEAD^ &&
94 + git rebase @{-1} >expect.messages &&
95 + git merge-base master HEAD >expect.forkpoint &&
96 +
97 + git checkout master &&
98 + git checkout HEAD^ &&
99 + git rebase - >actual.messages &&
100 + git merge-base master HEAD >actual.forkpoint &&
101 +
102 + test_cmp expect.forkpoint actual.forkpoint &&
103 + # the next one is dubious---we may want to say "-",
104 + # instead of @{-1}, in the message
105 + test_i18ncmp expect.messages actual.messages
106 +'
107 +
108 test_expect_success 'rebase a single mode change' '
109 git checkout master &&
110 git branch -D topic &&