Browse Source
"git checkout --to" sets up a new working directory with a .git file pointing to $GIT_DIR/worktrees/<id>. It then executes "git checkout" again on the new worktree with the same arguments except "--to" is taken out. The second checkout execution, which is not contaminated with any info from the current repository, will actually check out and everything that normal "git checkout" does. Helped-by: Marc Branchaud <marcnarc@xiplink.com> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>maint
Nguyễn Thái Ngọc Duy
10 years ago
committed by
Junio C Hamano
6 changed files with 212 additions and 4 deletions
@ -0,0 +1,63 @@ |
|||||||
|
#!/bin/sh |
||||||
|
|
||||||
|
test_description='test git checkout --to' |
||||||
|
|
||||||
|
. ./test-lib.sh |
||||||
|
|
||||||
|
test_expect_success 'setup' ' |
||||||
|
test_commit init |
||||||
|
' |
||||||
|
|
||||||
|
test_expect_success 'checkout --to not updating paths' ' |
||||||
|
test_must_fail git checkout --to -- init.t |
||||||
|
' |
||||||
|
|
||||||
|
test_expect_success 'checkout --to an existing worktree' ' |
||||||
|
mkdir existing && |
||||||
|
test_must_fail git checkout --detach --to existing master |
||||||
|
' |
||||||
|
|
||||||
|
test_expect_success 'checkout --to a new worktree' ' |
||||||
|
git checkout --to here master && |
||||||
|
( |
||||||
|
cd here && |
||||||
|
test_cmp ../init.t init.t && |
||||||
|
git symbolic-ref HEAD >actual && |
||||||
|
echo refs/heads/master >expect && |
||||||
|
test_cmp expect actual && |
||||||
|
git fsck |
||||||
|
) |
||||||
|
' |
||||||
|
|
||||||
|
test_expect_success 'checkout --to a new worktree from a subdir' ' |
||||||
|
( |
||||||
|
mkdir sub && |
||||||
|
cd sub && |
||||||
|
git checkout --detach --to here master && |
||||||
|
cd here && |
||||||
|
test_cmp ../../init.t init.t |
||||||
|
) |
||||||
|
' |
||||||
|
|
||||||
|
test_expect_success 'checkout --to from a linked checkout' ' |
||||||
|
( |
||||||
|
cd here && |
||||||
|
git checkout --to nested-here master && |
||||||
|
cd nested-here && |
||||||
|
git fsck |
||||||
|
) |
||||||
|
' |
||||||
|
|
||||||
|
test_expect_success 'checkout --to a new worktree creating new branch' ' |
||||||
|
git checkout --to there -b newmaster master && |
||||||
|
( |
||||||
|
cd there && |
||||||
|
test_cmp ../init.t init.t && |
||||||
|
git symbolic-ref HEAD >actual && |
||||||
|
echo refs/heads/newmaster >expect && |
||||||
|
test_cmp expect actual && |
||||||
|
git fsck |
||||||
|
) |
||||||
|
' |
||||||
|
|
||||||
|
test_done |
Loading…
Reference in new issue