]>
Commit | Line | Data |
---|---|---|
58142c09 NTND |
1 | #!/bin/sh |
2 | ||
3 | test_description='test git worktree move, remove, lock and unlock' | |
4 | ||
5 | . ./test-lib.sh | |
6 | ||
7 | test_expect_success 'setup' ' | |
8 | test_commit init && | |
9 | git worktree add source && | |
7f19def0 ES |
10 | git worktree list --porcelain >out && |
11 | grep "^worktree" out >actual && | |
58142c09 NTND |
12 | cat <<-EOF >expected && |
13 | worktree $(pwd) | |
14 | worktree $(pwd)/source | |
15 | EOF | |
16 | test_cmp expected actual | |
17 | ' | |
18 | ||
19 | test_expect_success 'lock main worktree' ' | |
20 | test_must_fail git worktree lock . | |
21 | ' | |
22 | ||
23 | test_expect_success 'lock linked worktree' ' | |
24 | git worktree lock --reason hahaha source && | |
25 | echo hahaha >expected && | |
26 | test_cmp expected .git/worktrees/source/locked | |
27 | ' | |
28 | ||
29 | test_expect_success 'lock linked worktree from another worktree' ' | |
30 | rm .git/worktrees/source/locked && | |
31 | git worktree add elsewhere && | |
32 | git -C elsewhere worktree lock --reason hahaha ../source && | |
33 | echo hahaha >expected && | |
34 | test_cmp expected .git/worktrees/source/locked | |
35 | ' | |
36 | ||
37 | test_expect_success 'lock worktree twice' ' | |
38 | test_must_fail git worktree lock source && | |
39 | echo hahaha >expected && | |
40 | test_cmp expected .git/worktrees/source/locked | |
41 | ' | |
42 | ||
43 | test_expect_success 'lock worktree twice (from the locked worktree)' ' | |
44 | test_must_fail git -C source worktree lock . && | |
45 | echo hahaha >expected && | |
46 | test_cmp expected .git/worktrees/source/locked | |
47 | ' | |
48 | ||
6d308627 NTND |
49 | test_expect_success 'unlock main worktree' ' |
50 | test_must_fail git worktree unlock . | |
51 | ' | |
52 | ||
53 | test_expect_success 'unlock linked worktree' ' | |
54 | git worktree unlock source && | |
55 | test_path_is_missing .git/worktrees/source/locked | |
56 | ' | |
57 | ||
58 | test_expect_success 'unlock worktree twice' ' | |
59 | test_must_fail git worktree unlock source && | |
60 | test_path_is_missing .git/worktrees/source/locked | |
61 | ' | |
62 | ||
9f792bb4 NTND |
63 | test_expect_success 'move non-worktree' ' |
64 | mkdir abc && | |
65 | test_must_fail git worktree move abc def | |
66 | ' | |
67 | ||
68 | test_expect_success 'move locked worktree' ' | |
69 | git worktree lock source && | |
70 | test_when_finished "git worktree unlock source" && | |
71 | test_must_fail git worktree move source destination | |
72 | ' | |
73 | ||
74 | test_expect_success 'move worktree' ' | |
9f792bb4 NTND |
75 | git worktree move source destination && |
76 | test_path_is_missing source && | |
7f19def0 | 77 | git worktree list --porcelain >out && |
b1801b85 ES |
78 | grep "^worktree.*/destination$" out && |
79 | ! grep "^worktree.*/source$" out && | |
9f792bb4 NTND |
80 | git -C destination log --format=%s >actual2 && |
81 | echo init >expected2 && | |
82 | test_cmp expected2 actual2 | |
83 | ' | |
84 | ||
85 | test_expect_success 'move main worktree' ' | |
86 | test_must_fail git worktree move . def | |
87 | ' | |
88 | ||
c64a8d20 | 89 | test_expect_success 'move worktree to another dir' ' |
c64a8d20 NTND |
90 | mkdir some-dir && |
91 | git worktree move destination some-dir && | |
7f19def0 ES |
92 | test_when_finished "git worktree move some-dir/destination destination" && |
93 | test_path_is_missing destination && | |
94 | git worktree list --porcelain >out && | |
b1801b85 | 95 | grep "^worktree.*/some-dir/destination$" out && |
c64a8d20 NTND |
96 | git -C some-dir/destination log --format=%s >actual2 && |
97 | echo init >expected2 && | |
98 | test_cmp expected2 actual2 | |
99 | ' | |
100 | ||
68a6b3a1 ES |
101 | test_expect_success 'move locked worktree (force)' ' |
102 | test_when_finished " | |
103 | git worktree unlock flump || : | |
104 | git worktree remove flump || : | |
105 | git worktree unlock ploof || : | |
106 | git worktree remove ploof || : | |
107 | " && | |
108 | git worktree add --detach flump && | |
109 | git worktree lock flump && | |
110 | test_must_fail git worktree move flump ploof" && | |
111 | test_must_fail git worktree move --force flump ploof" && | |
112 | git worktree move --force --force flump ploof | |
113 | ' | |
114 | ||
cc73385c NTND |
115 | test_expect_success 'remove main worktree' ' |
116 | test_must_fail git worktree remove . | |
117 | ' | |
118 | ||
cc73385c NTND |
119 | test_expect_success 'remove locked worktree' ' |
120 | git worktree lock destination && | |
121 | test_when_finished "git worktree unlock destination" && | |
122 | test_must_fail git worktree remove destination | |
123 | ' | |
124 | ||
125 | test_expect_success 'remove worktree with dirty tracked file' ' | |
126 | echo dirty >>destination/init.t && | |
127 | test_when_finished "git -C destination checkout init.t" && | |
128 | test_must_fail git worktree remove destination | |
129 | ' | |
130 | ||
131 | test_expect_success 'remove worktree with untracked file' ' | |
132 | : >destination/untracked && | |
133 | test_must_fail git worktree remove destination | |
134 | ' | |
135 | ||
136 | test_expect_success 'force remove worktree with untracked file' ' | |
137 | git worktree remove --force destination && | |
138 | test_path_is_missing destination | |
139 | ' | |
140 | ||
ee6763af NTND |
141 | test_expect_success 'remove missing worktree' ' |
142 | git worktree add to-be-gone && | |
143 | test -d .git/worktrees/to-be-gone && | |
144 | mv to-be-gone gone && | |
145 | git worktree remove to-be-gone && | |
146 | test_path_is_missing .git/worktrees/to-be-gone | |
147 | ' | |
148 | ||
149 | test_expect_success 'NOT remove missing-but-locked worktree' ' | |
150 | git worktree add gone-but-locked && | |
151 | git worktree lock gone-but-locked && | |
152 | test -d .git/worktrees/gone-but-locked && | |
153 | mv gone-but-locked really-gone-now && | |
154 | test_must_fail git worktree remove gone-but-locked && | |
155 | test_path_is_dir .git/worktrees/gone-but-locked | |
156 | ' | |
157 | ||
4c5fa9e6 ES |
158 | test_expect_success 'proper error when worktree not found' ' |
159 | for i in noodle noodle/bork | |
160 | do | |
161 | test_must_fail git worktree lock $i 2>err && | |
162 | test_i18ngrep "not a working tree" err || return 1 | |
163 | done | |
164 | ' | |
165 | ||
f4143101 ES |
166 | test_expect_success 'remove locked worktree (force)' ' |
167 | git worktree add --detach gumby && | |
168 | test_when_finished "git worktree remove gumby || :" && | |
169 | git worktree lock gumby && | |
170 | test_when_finished "git worktree unlock gumby || :" && | |
171 | test_must_fail git worktree remove gumby && | |
172 | test_must_fail git worktree remove --force gumby && | |
173 | git worktree remove --force --force gumby | |
174 | ' | |
175 | ||
3a540433 ES |
176 | test_expect_success 'remove cleans up .git/worktrees when empty' ' |
177 | git init moog && | |
178 | ( | |
179 | cd moog && | |
180 | test_commit bim && | |
181 | git worktree add --detach goom && | |
182 | test_path_exists .git/worktrees && | |
183 | git worktree remove goom && | |
184 | test_path_is_missing .git/worktrees | |
185 | ) | |
186 | ' | |
187 | ||
58142c09 | 188 | test_done |