diff options
author | Denton Liu <liu.denton@gmail.com> | 2019-04-27 15:02:22 +0300 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2019-05-07 07:23:13 +0300 |
commit | e3d6539d58238f046ff955330f6e10c447150164 (patch) | |
tree | a80e3a6d2e4814bf8b750edc027a05ed90d1e15e /t/t2018-checkout-branch.sh | |
parent | 27434bf08c6c7c065e6323e8aa3f285d8f345e83 (diff) |
branch: make create_branch accept a merge base rev
When we ran something like
$ git checkout -b test master...
it would fail with the message
fatal: Not a valid object name: 'master...'.
This was caused by the call to `create_branch` where `start_name` is
expected to be a valid rev. However, git-checkout allows the branch to
be a valid _merge base_ rev (i.e. with a "...") so it was possible for
an invalid rev to be passed in.
Make `create_branch` accept a merge base rev so that this case does not
error out.
As a side-effect, teach git-branch how to handle merge base revs as
well.
Helped-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Denton Liu <liu.denton@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 't/t2018-checkout-branch.sh')
-rwxr-xr-x | t/t2018-checkout-branch.sh | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/t/t2018-checkout-branch.sh b/t/t2018-checkout-branch.sh index f1c7023e1a..822381dd9d 100755 --- a/t/t2018-checkout-branch.sh +++ b/t/t2018-checkout-branch.sh @@ -66,6 +66,13 @@ test_expect_success 'checkout -b to a new branch, set to HEAD' ' do_checkout branch2 ' +test_expect_success 'checkout -b to a merge base' ' + test_when_finished " + git checkout branch1 && + test_might_fail git branch -D branch2" && + git checkout -b branch2 branch1... +' + test_expect_success 'checkout -b to a new branch, set to an explicit ref' ' test_when_finished " git checkout branch1 && @@ -126,6 +133,12 @@ test_expect_success 'checkout -B to an existing branch resets branch to HEAD' ' do_checkout branch2 "" -B ' +test_expect_success 'checkout -B to a merge base' ' + git checkout branch1 && + + git checkout -B branch2 branch1... +' + test_expect_success 'checkout -B to an existing branch from detached HEAD resets branch to HEAD' ' git checkout $(git rev-parse --verify HEAD) && |