]>
Commit | Line | Data |
---|---|---|
529fef20 NTND |
1 | #!/bin/sh |
2 | ||
f194b1ef | 3 | test_description='test git worktree add' |
529fef20 NTND |
4 | |
5 | . ./test-lib.sh | |
6 | ||
7 | test_expect_success 'setup' ' | |
8 | test_commit init | |
9 | ' | |
10 | ||
f194b1ef | 11 | test_expect_success '"add" an existing worktree' ' |
ee4fb843 | 12 | mkdir -p existing/subtree && |
f194b1ef | 13 | test_must_fail git worktree add --detach existing master |
529fef20 NTND |
14 | ' |
15 | ||
f194b1ef | 16 | test_expect_success '"add" an existing empty worktree' ' |
ee4fb843 | 17 | mkdir existing_empty && |
f194b1ef | 18 | git worktree add --detach existing_empty master |
ee4fb843 MK |
19 | ' |
20 | ||
f194b1ef ES |
21 | test_expect_success '"add" refuses to checkout locked branch' ' |
22 | test_must_fail git worktree add zere master && | |
3b8925c7 NTND |
23 | ! test -d zere && |
24 | ! test -d .git/worktrees/zere | |
25 | ' | |
26 | ||
e1c1ab9d NTND |
27 | test_expect_success 'checking out paths not complaining about linked checkouts' ' |
28 | ( | |
29 | cd existing_empty && | |
30 | echo dirty >>init.t && | |
31 | git checkout master -- init.t | |
32 | ) | |
33 | ' | |
34 | ||
f194b1ef | 35 | test_expect_success '"add" worktree' ' |
5883034c | 36 | git rev-parse HEAD >expect && |
f194b1ef | 37 | git worktree add --detach here master && |
529fef20 NTND |
38 | ( |
39 | cd here && | |
40 | test_cmp ../init.t init.t && | |
5883034c NTND |
41 | test_must_fail git symbolic-ref HEAD && |
42 | git rev-parse HEAD >actual && | |
43 | test_cmp ../expect actual && | |
529fef20 NTND |
44 | git fsck |
45 | ) | |
46 | ' | |
47 | ||
f194b1ef | 48 | test_expect_success '"add" worktree from a subdir' ' |
529fef20 NTND |
49 | ( |
50 | mkdir sub && | |
51 | cd sub && | |
f194b1ef | 52 | git worktree add --detach here master && |
529fef20 NTND |
53 | cd here && |
54 | test_cmp ../../init.t init.t | |
55 | ) | |
56 | ' | |
57 | ||
f194b1ef | 58 | test_expect_success '"add" from a linked checkout' ' |
529fef20 NTND |
59 | ( |
60 | cd here && | |
f194b1ef | 61 | git worktree add --detach nested-here master && |
529fef20 NTND |
62 | cd nested-here && |
63 | git fsck | |
64 | ) | |
65 | ' | |
66 | ||
f194b1ef ES |
67 | test_expect_success '"add" worktree creating new branch' ' |
68 | git worktree add -b newmaster there master && | |
529fef20 NTND |
69 | ( |
70 | cd there && | |
71 | test_cmp ../init.t init.t && | |
72 | git symbolic-ref HEAD >actual && | |
73 | echo refs/heads/newmaster >expect && | |
74 | test_cmp expect actual && | |
75 | git fsck | |
76 | ) | |
77 | ' | |
78 | ||
5883034c NTND |
79 | test_expect_success 'die the same branch is already checked out' ' |
80 | ( | |
81 | cd here && | |
82 | test_must_fail git checkout newmaster | |
83 | ) | |
84 | ' | |
85 | ||
1d0fa898 NTND |
86 | test_expect_success 'not die the same branch is already checked out' ' |
87 | ( | |
88 | cd here && | |
f194b1ef | 89 | git worktree add --force anothernewmaster newmaster |
1d0fa898 NTND |
90 | ) |
91 | ' | |
92 | ||
5883034c NTND |
93 | test_expect_success 'not die on re-checking out current branch' ' |
94 | ( | |
95 | cd there && | |
96 | git checkout newmaster | |
97 | ) | |
98 | ' | |
99 | ||
f194b1ef | 100 | test_expect_success '"add" from a bare repo' ' |
3473ad0c DK |
101 | ( |
102 | git clone --bare . bare && | |
103 | cd bare && | |
f194b1ef | 104 | git worktree add -b bare-master ../there2 master |
3473ad0c DK |
105 | ) |
106 | ' | |
107 | ||
f194b1ef | 108 | test_expect_success 'checkout from a bare repo without "add"' ' |
3473ad0c DK |
109 | ( |
110 | cd bare && | |
111 | test_must_fail git checkout master | |
112 | ) | |
113 | ' | |
114 | ||
ad35f615 NTND |
115 | test_expect_success 'checkout with grafts' ' |
116 | test_when_finished rm .git/info/grafts && | |
117 | test_commit abc && | |
118 | SHA1=`git rev-parse HEAD` && | |
119 | test_commit def && | |
120 | test_commit xyz && | |
121 | echo "`git rev-parse HEAD` $SHA1" >.git/info/grafts && | |
122 | cat >expected <<-\EOF && | |
123 | xyz | |
124 | abc | |
125 | EOF | |
126 | git log --format=%s -2 >actual && | |
127 | test_cmp expected actual && | |
f194b1ef | 128 | git worktree add --detach grafted master && |
ad35f615 NTND |
129 | git --git-dir=grafted/.git log --format=%s -2 >actual && |
130 | test_cmp expected actual | |
131 | ' | |
132 | ||
f194b1ef | 133 | test_expect_success '"add" from relative HEAD' ' |
c990a4c1 ES |
134 | test_commit a && |
135 | test_commit b && | |
136 | test_commit c && | |
137 | git rev-parse HEAD~1 >expected && | |
f194b1ef | 138 | git worktree add relhead HEAD~1 && |
c990a4c1 ES |
139 | git -C relhead rev-parse HEAD >actual && |
140 | test_cmp expected actual | |
141 | ' | |
142 | ||
0f4af3b9 ES |
143 | test_expect_success '"add -b" with <branch> omitted' ' |
144 | git worktree add -b burble flornk && | |
145 | test_cmp_rev HEAD burble | |
146 | ' | |
147 | ||
1eb07d82 ES |
148 | test_expect_success '"add" with <branch> omitted' ' |
149 | git worktree add wiffle/bat && | |
150 | test_cmp_rev HEAD bat | |
151 | ' | |
152 | ||
153 | test_expect_success '"add" auto-vivify does not clobber existing branch' ' | |
154 | test_commit c1 && | |
155 | test_commit c2 && | |
156 | git branch precious HEAD~1 && | |
157 | test_must_fail git worktree add precious && | |
158 | test_cmp_rev HEAD~1 precious && | |
159 | test_path_is_missing precious | |
160 | ' | |
161 | ||
529fef20 | 162 | test_done |