]>
Commit | Line | Data |
---|---|---|
529fef20 NTND |
1 | #!/bin/sh |
2 | ||
3 | test_description='test git checkout --to' | |
4 | ||
5 | . ./test-lib.sh | |
6 | ||
7 | test_expect_success 'setup' ' | |
8 | test_commit init | |
9 | ' | |
10 | ||
11 | test_expect_success 'checkout --to not updating paths' ' | |
12 | test_must_fail git checkout --to -- init.t | |
13 | ' | |
14 | ||
15 | test_expect_success 'checkout --to an existing worktree' ' | |
16 | mkdir existing && | |
17 | test_must_fail git checkout --detach --to existing master | |
18 | ' | |
19 | ||
3b8925c7 NTND |
20 | test_expect_success 'checkout --to refuses to checkout locked branch' ' |
21 | test_must_fail git checkout --to zere master && | |
22 | ! test -d zere && | |
23 | ! test -d .git/worktrees/zere | |
24 | ' | |
25 | ||
529fef20 | 26 | test_expect_success 'checkout --to a new worktree' ' |
5883034c NTND |
27 | git rev-parse HEAD >expect && |
28 | git checkout --detach --to here master && | |
529fef20 NTND |
29 | ( |
30 | cd here && | |
31 | test_cmp ../init.t init.t && | |
5883034c NTND |
32 | test_must_fail git symbolic-ref HEAD && |
33 | git rev-parse HEAD >actual && | |
34 | test_cmp ../expect actual && | |
529fef20 NTND |
35 | git fsck |
36 | ) | |
37 | ' | |
38 | ||
39 | test_expect_success 'checkout --to a new worktree from a subdir' ' | |
40 | ( | |
41 | mkdir sub && | |
42 | cd sub && | |
43 | git checkout --detach --to here master && | |
44 | cd here && | |
45 | test_cmp ../../init.t init.t | |
46 | ) | |
47 | ' | |
48 | ||
49 | test_expect_success 'checkout --to from a linked checkout' ' | |
50 | ( | |
51 | cd here && | |
5883034c | 52 | git checkout --detach --to nested-here master && |
529fef20 NTND |
53 | cd nested-here && |
54 | git fsck | |
55 | ) | |
56 | ' | |
57 | ||
58 | test_expect_success 'checkout --to a new worktree creating new branch' ' | |
59 | git checkout --to there -b newmaster master && | |
60 | ( | |
61 | cd there && | |
62 | test_cmp ../init.t init.t && | |
63 | git symbolic-ref HEAD >actual && | |
64 | echo refs/heads/newmaster >expect && | |
65 | test_cmp expect actual && | |
66 | git fsck | |
67 | ) | |
68 | ' | |
69 | ||
5883034c NTND |
70 | test_expect_success 'die the same branch is already checked out' ' |
71 | ( | |
72 | cd here && | |
73 | test_must_fail git checkout newmaster | |
74 | ) | |
75 | ' | |
76 | ||
77 | test_expect_success 'not die on re-checking out current branch' ' | |
78 | ( | |
79 | cd there && | |
80 | git checkout newmaster | |
81 | ) | |
82 | ' | |
83 | ||
3473ad0c DK |
84 | test_expect_success 'checkout --to from a bare repo' ' |
85 | ( | |
86 | git clone --bare . bare && | |
87 | cd bare && | |
88 | git checkout --to ../there2 -b bare-master master | |
89 | ) | |
90 | ' | |
91 | ||
92 | test_expect_success 'checkout from a bare repo without --to' ' | |
93 | ( | |
94 | cd bare && | |
95 | test_must_fail git checkout master | |
96 | ) | |
97 | ' | |
98 | ||
529fef20 | 99 | test_done |