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>
This commit is contained in:

committed by
Junio C Hamano

parent
27434bf08c
commit
e3d6539d58
@ -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) &&
|
||||
|
||||
|
@ -42,6 +42,10 @@ test_expect_success 'git branch a/b/c should create a branch' '
|
||||
git branch a/b/c && test_path_is_file .git/refs/heads/a/b/c
|
||||
'
|
||||
|
||||
test_expect_success 'git branch mb master... should create a branch' '
|
||||
git branch mb master... && test_path_is_file .git/refs/heads/mb
|
||||
'
|
||||
|
||||
test_expect_success 'git branch HEAD should fail' '
|
||||
test_must_fail git branch HEAD
|
||||
'
|
||||
@ -292,8 +296,8 @@ test_expect_success 'git branch --list -v with --abbrev' '
|
||||
test_expect_success 'git branch --column' '
|
||||
COLUMNS=81 git branch --column=column >actual &&
|
||||
cat >expected <<\EOF &&
|
||||
a/b/c bam foo l * master n o/p r
|
||||
abc bar j/k m/m master2 o/o q
|
||||
a/b/c bam foo l * master mb o/o q
|
||||
abc bar j/k m/m master2 n o/p r
|
||||
EOF
|
||||
test_cmp expected actual
|
||||
'
|
||||
@ -315,6 +319,7 @@ test_expect_success 'git branch --column with an extremely long branch name' '
|
||||
m/m
|
||||
* master
|
||||
master2
|
||||
mb
|
||||
n
|
||||
o/o
|
||||
o/p
|
||||
@ -332,8 +337,8 @@ test_expect_success 'git branch with column.*' '
|
||||
git config --unset column.branch &&
|
||||
git config --unset column.ui &&
|
||||
cat >expected <<\EOF &&
|
||||
a/b/c bam foo l * master n o/p r
|
||||
abc bar j/k m/m master2 o/o q
|
||||
a/b/c bam foo l * master mb o/o q
|
||||
abc bar j/k m/m master2 n o/p r
|
||||
EOF
|
||||
test_cmp expected actual
|
||||
'
|
||||
@ -357,6 +362,7 @@ test_expect_success 'git branch -v with column.ui ignored' '
|
||||
m/m
|
||||
* master
|
||||
master2
|
||||
mb
|
||||
n
|
||||
o/o
|
||||
o/p
|
||||
|
Reference in New Issue
Block a user