mirror of
https://github.com/git/git.git
synced 2024-11-28 20:44:04 +08:00
3442ea4a75
"git checkout -b newbranch $commit^{tree}" mistakenly created a new branch rooted at the current HEAD, because in that case, the two structure fields used to see if the command was invoked without any argument (hence it needs to default to checking out the HEAD) were populated incorrectly. Upon seeing a command line argument that we took as a rev, we should store that string in new.name, even if that does not name a commit. This will correctly trigger the existing safety logic. Signed-off-by: Junio C Hamano <gitster@pobox.com> Acked-by: Daniel Barkalow <barkalow@iabervon.org>
23 lines
475 B
Bash
Executable File
23 lines
475 B
Bash
Executable File
#!/bin/sh
|
|
|
|
test_description='checkout switching away from an invalid branch'
|
|
|
|
. ./test-lib.sh
|
|
|
|
test_expect_success 'setup' '
|
|
echo hello >world &&
|
|
git add world &&
|
|
git commit -m initial
|
|
'
|
|
|
|
test_expect_success 'checkout should not start branch from a tree' '
|
|
test_must_fail git checkout -b newbranch master^{tree}
|
|
'
|
|
|
|
test_expect_success 'checkout master from invalid HEAD' '
|
|
echo 0000000000000000000000000000000000000000 >.git/HEAD &&
|
|
git checkout master --
|
|
'
|
|
|
|
test_done
|