rebase: allow "-" short-hand for the previous branch
authorBrian Gesiak <modocache@gmail.com>
Wed, 19 Mar 2014 11:02:15 +0000 (20:02 +0900)
committerJunio C Hamano <gitster@pobox.com>
Wed, 19 Mar 2014 17:52:51 +0000 (10:52 -0700)
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>
git-rebase.sh
t/t3400-rebase.sh
index 8a3efa2983d08e38d40ae8b6dcecd82b0901ffa1..658c003c14d836b260a6f8057894315913d3451c 100755 (executable)
@@ -449,6 +449,10 @@ then
                test "$fork_point" = auto && fork_point=t
                ;;
        *)      upstream_name="$1"
+               if test "$upstream_name" = "-"
+               then
+                       upstream_name="@{-1}"
+               fi
                shift
                ;;
        esac
index 6d94b1fcd94e9f724c93a389c50066c92c46e1b9..80e0a951ea3b699dc57530c1749a2e727ec6779d 100755 (executable)
@@ -88,6 +88,23 @@ test_expect_success 'rebase from ambiguous branch name' '
        git rebase master
 '
 
+test_expect_success 'rebase off of the previous branch using "-"' '
+       git checkout master &&
+       git checkout HEAD^ &&
+       git rebase @{-1} >expect.messages &&
+       git merge-base master HEAD >expect.forkpoint &&
+
+       git checkout master &&
+       git checkout HEAD^ &&
+       git rebase - >actual.messages &&
+       git merge-base master HEAD >actual.forkpoint &&
+
+       test_cmp expect.forkpoint actual.forkpoint &&
+       # the next one is dubious---we may want to say "-",
+       # instead of @{-1}, in the message
+       test_i18ncmp expect.messages actual.messages
+'
+
 test_expect_success 'rebase a single mode change' '
        git checkout master &&
        git branch -D topic &&