Sync with 2.4.3
[git.git] / t / t2025-checkout-to.sh
blobf8e4df4818523de74ff7330f015415bfb9cc8227
1 #!/bin/sh
3 test_description='test git checkout --to'
5 . ./test-lib.sh
7 test_expect_success 'setup' '
8 test_commit init
11 test_expect_success 'checkout --to not updating paths' '
12 test_must_fail git checkout --to -- init.t
15 test_expect_success 'checkout --to an existing worktree' '
16 mkdir -p existing/subtree &&
17 test_must_fail git checkout --detach --to existing master
20 test_expect_success 'checkout --to an existing empty worktree' '
21 mkdir existing_empty &&
22 git checkout --detach --to existing_empty master
25 test_expect_success 'checkout --to refuses to checkout locked branch' '
26 test_must_fail git checkout --to zere master &&
27 ! test -d zere &&
28 ! test -d .git/worktrees/zere
31 test_expect_success 'checkout --to a new worktree' '
32 git rev-parse HEAD >expect &&
33 git checkout --detach --to here master &&
35 cd here &&
36 test_cmp ../init.t init.t &&
37 test_must_fail git symbolic-ref HEAD &&
38 git rev-parse HEAD >actual &&
39 test_cmp ../expect actual &&
40 git fsck
44 test_expect_success 'checkout --to a new worktree from a subdir' '
46 mkdir sub &&
47 cd sub &&
48 git checkout --detach --to here master &&
49 cd here &&
50 test_cmp ../../init.t init.t
54 test_expect_success 'checkout --to from a linked checkout' '
56 cd here &&
57 git checkout --detach --to nested-here master &&
58 cd nested-here &&
59 git fsck
63 test_expect_success 'checkout --to a new worktree creating new branch' '
64 git checkout --to there -b newmaster master &&
66 cd there &&
67 test_cmp ../init.t init.t &&
68 git symbolic-ref HEAD >actual &&
69 echo refs/heads/newmaster >expect &&
70 test_cmp expect actual &&
71 git fsck
75 test_expect_success 'die the same branch is already checked out' '
77 cd here &&
78 test_must_fail git checkout newmaster
82 test_expect_success 'not die the same branch is already checked out' '
84 cd here &&
85 git checkout --ignore-other-worktrees --to anothernewmaster newmaster
89 test_expect_success 'not die on re-checking out current branch' '
91 cd there &&
92 git checkout newmaster
96 test_expect_success 'checkout --to from a bare repo' '
98 git clone --bare . bare &&
99 cd bare &&
100 git checkout --to ../there2 -b bare-master master
104 test_expect_success 'checkout from a bare repo without --to' '
106 cd bare &&
107 test_must_fail git checkout master
111 test_expect_success 'checkout with grafts' '
112 test_when_finished rm .git/info/grafts &&
113 test_commit abc &&
114 SHA1=`git rev-parse HEAD` &&
115 test_commit def &&
116 test_commit xyz &&
117 echo "`git rev-parse HEAD` $SHA1" >.git/info/grafts &&
118 cat >expected <<-\EOF &&
122 git log --format=%s -2 >actual &&
123 test_cmp expected actual &&
124 git checkout --detach --to grafted master &&
125 git --git-dir=grafted/.git log --format=%s -2 >actual &&
126 test_cmp expected actual
129 test_done