]>
Commit | Line | Data |
---|---|---|
27bfd950 PY |
1 | #!/bin/sh |
2 | ||
47a528ad | 3 | test_description='git status for submodule' |
27bfd950 | 4 | |
e77b3da6 | 5 | TEST_PASSES_SANITIZE_LEAK=true |
27bfd950 PY |
6 | . ./test-lib.sh |
7 | ||
44ca0c8e HV |
8 | test_create_repo_with_commit () { |
9 | test_create_repo "$1" && | |
ee6fc514 | 10 | ( |
44ca0c8e | 11 | cd "$1" && |
ee6fc514 JL |
12 | : >bar && |
13 | git add bar && | |
14 | git commit -m " Add bar" && | |
15 | : >foo && | |
16 | git add foo && | |
17 | git commit -m " Add foo" | |
44ca0c8e HV |
18 | ) |
19 | } | |
20 | ||
dd6962dd | 21 | sanitize_output () { |
2ece6ad2 | 22 | sed -e "s/$OID_REGEX/HASH/" -e "s/$OID_REGEX/HASH/" output >output2 && |
dd6962dd SB |
23 | mv output2 output |
24 | } | |
25 | ||
66b6d43c | 26 | sanitize_diff () { |
27 | sed -e "/^index [0-9a-f,]*\.\.[0-9a-f]*/d" "$1" | |
28 | } | |
29 | ||
dd6962dd | 30 | |
44ca0c8e HV |
31 | test_expect_success 'setup' ' |
32 | test_create_repo_with_commit sub && | |
ee6fc514 JL |
33 | echo output > .gitignore && |
34 | git add sub .gitignore && | |
27bfd950 PY |
35 | git commit -m "Add submodule sub" |
36 | ' | |
37 | ||
7a23d2d2 | 38 | test_expect_success 'status clean' ' |
ee6fc514 | 39 | git status >output && |
7a23d2d2 | 40 | test_i18ngrep "nothing to commit" output |
27bfd950 | 41 | ' |
ee6fc514 | 42 | |
7a23d2d2 | 43 | test_expect_success 'commit --dry-run -a clean' ' |
ee6fc514 | 44 | test_must_fail git commit --dry-run -a >output && |
7a23d2d2 | 45 | test_i18ngrep "nothing to commit" output |
ee6fc514 JL |
46 | ' |
47 | ||
7a23d2d2 | 48 | test_expect_success 'status with modified file in submodule' ' |
ee6fc514 JL |
49 | (cd sub && git reset --hard) && |
50 | echo "changed" >sub/foo && | |
51 | git status >output && | |
7a23d2d2 | 52 | test_i18ngrep "modified: sub (modified content)" output |
ee6fc514 JL |
53 | ' |
54 | ||
55 | test_expect_success 'status with modified file in submodule (porcelain)' ' | |
56 | (cd sub && git reset --hard) && | |
57 | echo "changed" >sub/foo && | |
58 | git status --porcelain >output && | |
59 | diff output - <<-\EOF | |
60 | M sub | |
61 | EOF | |
62 | ' | |
63 | ||
dd6962dd SB |
64 | test_expect_success 'status with modified file in submodule (short)' ' |
65 | (cd sub && git reset --hard) && | |
66 | echo "changed" >sub/foo && | |
67 | git status --short >output && | |
68 | diff output - <<-\EOF | |
69 | m sub | |
70 | EOF | |
71 | ' | |
72 | ||
7a23d2d2 | 73 | test_expect_success 'status with added file in submodule' ' |
ee6fc514 JL |
74 | (cd sub && git reset --hard && echo >foo && git add foo) && |
75 | git status >output && | |
7a23d2d2 | 76 | test_i18ngrep "modified: sub (modified content)" output |
ee6fc514 JL |
77 | ' |
78 | ||
79 | test_expect_success 'status with added file in submodule (porcelain)' ' | |
80 | (cd sub && git reset --hard && echo >foo && git add foo) && | |
81 | git status --porcelain >output && | |
82 | diff output - <<-\EOF | |
83 | M sub | |
84 | EOF | |
85 | ' | |
86 | ||
dd6962dd SB |
87 | test_expect_success 'status with added file in submodule (short)' ' |
88 | (cd sub && git reset --hard && echo >foo && git add foo) && | |
89 | git status --short >output && | |
90 | diff output - <<-\EOF | |
91 | m sub | |
92 | EOF | |
93 | ' | |
94 | ||
7a23d2d2 | 95 | test_expect_success 'status with untracked file in submodule' ' |
ee6fc514 JL |
96 | (cd sub && git reset --hard) && |
97 | echo "content" >sub/new-file && | |
98 | git status >output && | |
7a23d2d2 | 99 | test_i18ngrep "modified: sub (untracked content)" output |
ee6fc514 JL |
100 | ' |
101 | ||
7a23d2d2 | 102 | test_expect_success 'status -uno with untracked file in submodule' ' |
3bfc4504 | 103 | git status -uno >output && |
7a23d2d2 | 104 | test_i18ngrep "^nothing to commit" output |
3bfc4504 JL |
105 | ' |
106 | ||
ee6fc514 JL |
107 | test_expect_success 'status with untracked file in submodule (porcelain)' ' |
108 | git status --porcelain >output && | |
109 | diff output - <<-\EOF | |
110 | M sub | |
111 | EOF | |
27bfd950 | 112 | ' |
ee6fc514 | 113 | |
dd6962dd SB |
114 | test_expect_success 'status with untracked file in submodule (short)' ' |
115 | git status --short >output && | |
116 | diff output - <<-\EOF | |
117 | ? sub | |
118 | EOF | |
119 | ' | |
120 | ||
7a23d2d2 | 121 | test_expect_success 'status with added and untracked file in submodule' ' |
85adbf2f JL |
122 | (cd sub && git reset --hard && echo >foo && git add foo) && |
123 | echo "content" >sub/new-file && | |
124 | git status >output && | |
7a23d2d2 | 125 | test_i18ngrep "modified: sub (modified content, untracked content)" output |
85adbf2f JL |
126 | ' |
127 | ||
128 | test_expect_success 'status with added and untracked file in submodule (porcelain)' ' | |
129 | (cd sub && git reset --hard && echo >foo && git add foo) && | |
130 | echo "content" >sub/new-file && | |
131 | git status --porcelain >output && | |
132 | diff output - <<-\EOF | |
133 | M sub | |
134 | EOF | |
135 | ' | |
136 | ||
7a23d2d2 | 137 | test_expect_success 'status with modified file in modified submodule' ' |
85adbf2f JL |
138 | (cd sub && git reset --hard) && |
139 | rm sub/new-file && | |
140 | (cd sub && echo "next change" >foo && git commit -m "next change" foo) && | |
141 | echo "changed" >sub/foo && | |
142 | git status >output && | |
7a23d2d2 | 143 | test_i18ngrep "modified: sub (new commits, modified content)" output |
85adbf2f JL |
144 | ' |
145 | ||
146 | test_expect_success 'status with modified file in modified submodule (porcelain)' ' | |
147 | (cd sub && git reset --hard) && | |
148 | echo "changed" >sub/foo && | |
149 | git status --porcelain >output && | |
150 | diff output - <<-\EOF | |
151 | M sub | |
152 | EOF | |
153 | ' | |
154 | ||
7a23d2d2 | 155 | test_expect_success 'status with added file in modified submodule' ' |
85adbf2f JL |
156 | (cd sub && git reset --hard && echo >foo && git add foo) && |
157 | git status >output && | |
7a23d2d2 | 158 | test_i18ngrep "modified: sub (new commits, modified content)" output |
85adbf2f JL |
159 | ' |
160 | ||
161 | test_expect_success 'status with added file in modified submodule (porcelain)' ' | |
162 | (cd sub && git reset --hard && echo >foo && git add foo) && | |
163 | git status --porcelain >output && | |
164 | diff output - <<-\EOF | |
165 | M sub | |
166 | EOF | |
167 | ' | |
168 | ||
7a23d2d2 | 169 | test_expect_success 'status with untracked file in modified submodule' ' |
85adbf2f JL |
170 | (cd sub && git reset --hard) && |
171 | echo "content" >sub/new-file && | |
172 | git status >output && | |
7a23d2d2 | 173 | test_i18ngrep "modified: sub (new commits, untracked content)" output |
85adbf2f JL |
174 | ' |
175 | ||
176 | test_expect_success 'status with untracked file in modified submodule (porcelain)' ' | |
177 | git status --porcelain >output && | |
178 | diff output - <<-\EOF | |
179 | M sub | |
180 | EOF | |
181 | ' | |
182 | ||
7a23d2d2 | 183 | test_expect_success 'status with added and untracked file in modified submodule' ' |
85adbf2f JL |
184 | (cd sub && git reset --hard && echo >foo && git add foo) && |
185 | echo "content" >sub/new-file && | |
186 | git status >output && | |
7a23d2d2 | 187 | test_i18ngrep "modified: sub (new commits, modified content, untracked content)" output |
85adbf2f JL |
188 | ' |
189 | ||
190 | test_expect_success 'status with added and untracked file in modified submodule (porcelain)' ' | |
191 | (cd sub && git reset --hard && echo >foo && git add foo) && | |
192 | echo "content" >sub/new-file && | |
193 | git status --porcelain >output && | |
194 | diff output - <<-\EOF | |
195 | M sub | |
196 | EOF | |
197 | ' | |
198 | ||
eee49b6c JL |
199 | test_expect_success 'setup .git file for sub' ' |
200 | (cd sub && | |
e974e06d | 201 | rm -f new-file && |
eee49b6c | 202 | REAL="$(pwd)/../.real" && |
e974e06d | 203 | mv .git "$REAL" && |
eee49b6c JL |
204 | echo "gitdir: $REAL" >.git) && |
205 | echo .real >>.gitignore && | |
206 | git commit -m "added .real to .gitignore" .gitignore | |
207 | ' | |
208 | ||
7a23d2d2 | 209 | test_expect_success 'status with added file in modified submodule with .git file' ' |
eee49b6c JL |
210 | (cd sub && git reset --hard && echo >foo && git add foo) && |
211 | git status >output && | |
7a23d2d2 | 212 | test_i18ngrep "modified: sub (new commits, modified content)" output |
eee49b6c JL |
213 | ' |
214 | ||
af6865a7 SB |
215 | test_expect_success 'status with a lot of untracked files in the submodule' ' |
216 | ( | |
e974e06d | 217 | cd sub && |
af6865a7 SB |
218 | i=0 && |
219 | while test $i -lt 1024 | |
220 | do | |
e974e06d ES |
221 | >some-file-$i && |
222 | i=$(( $i + 1 )) || exit 1 | |
af6865a7 SB |
223 | done |
224 | ) && | |
225 | git status --porcelain sub 2>err.actual && | |
226 | test_must_be_empty err.actual && | |
227 | rm err.actual | |
228 | ' | |
229 | ||
27bfd950 | 230 | test_expect_success 'rm submodule contents' ' |
af6865a7 SB |
231 | rm -rf sub && |
232 | mkdir sub | |
27bfd950 | 233 | ' |
ee6fc514 | 234 | |
7a23d2d2 | 235 | test_expect_success 'status clean (empty submodule dir)' ' |
ee6fc514 | 236 | git status >output && |
7a23d2d2 | 237 | test_i18ngrep "nothing to commit" output |
27bfd950 | 238 | ' |
ee6fc514 | 239 | |
7a23d2d2 | 240 | test_expect_success 'status -a clean (empty submodule dir)' ' |
ee6fc514 | 241 | test_must_fail git commit --dry-run -a >output && |
7a23d2d2 | 242 | test_i18ngrep "nothing to commit" output |
27bfd950 PY |
243 | ' |
244 | ||
44ca0c8e HV |
245 | cat >status_expect <<\EOF |
246 | AA .gitmodules | |
247 | A sub1 | |
248 | EOF | |
249 | ||
d4e98b58 | 250 | test_expect_success 'status with merge conflict in .gitmodules' ' |
44ca0c8e HV |
251 | git clone . super && |
252 | test_create_repo_with_commit sub1 && | |
253 | test_tick && | |
254 | test_create_repo_with_commit sub2 && | |
255 | ( | |
256 | cd super && | |
257 | prev=$(git rev-parse HEAD) && | |
258 | git checkout -b add_sub1 && | |
259 | git submodule add ../sub1 && | |
260 | git commit -m "add sub1" && | |
261 | git checkout -b add_sub2 $prev && | |
262 | git submodule add ../sub2 && | |
263 | git commit -m "add sub2" && | |
264 | git checkout -b merge_conflict_gitmodules && | |
265 | test_must_fail git merge add_sub1 && | |
266 | git status -s >../status_actual 2>&1 | |
267 | ) && | |
268 | test_cmp status_actual status_expect | |
269 | ' | |
270 | ||
271 | sha1_merge_sub1=$(cd sub1 && git rev-parse HEAD) | |
272 | sha1_merge_sub2=$(cd sub2 && git rev-parse HEAD) | |
273 | short_sha1_merge_sub1=$(cd sub1 && git rev-parse --short HEAD) | |
274 | short_sha1_merge_sub2=$(cd sub2 && git rev-parse --short HEAD) | |
275 | cat >diff_expect <<\EOF | |
276 | diff --cc .gitmodules | |
44ca0c8e HV |
277 | --- a/.gitmodules |
278 | +++ b/.gitmodules | |
279 | @@@ -1,3 -1,3 +1,9 @@@ | |
280 | ++<<<<<<< HEAD | |
281 | +[submodule "sub2"] | |
282 | + path = sub2 | |
283 | + url = ../sub2 | |
284 | ++======= | |
285 | + [submodule "sub1"] | |
286 | + path = sub1 | |
287 | + url = ../sub1 | |
288 | ++>>>>>>> add_sub1 | |
289 | EOF | |
290 | ||
291 | cat >diff_submodule_expect <<\EOF | |
292 | diff --cc .gitmodules | |
44ca0c8e HV |
293 | --- a/.gitmodules |
294 | +++ b/.gitmodules | |
295 | @@@ -1,3 -1,3 +1,9 @@@ | |
296 | ++<<<<<<< HEAD | |
297 | +[submodule "sub2"] | |
298 | + path = sub2 | |
299 | + url = ../sub2 | |
300 | ++======= | |
301 | + [submodule "sub1"] | |
302 | + path = sub1 | |
303 | + url = ../sub1 | |
304 | ++>>>>>>> add_sub1 | |
305 | EOF | |
306 | ||
d4e98b58 | 307 | test_expect_success 'diff with merge conflict in .gitmodules' ' |
44ca0c8e HV |
308 | ( |
309 | cd super && | |
310 | git diff >../diff_actual 2>&1 | |
311 | ) && | |
66b6d43c | 312 | sanitize_diff diff_actual >diff_sanitized && |
313 | test_cmp diff_expect diff_sanitized | |
44ca0c8e HV |
314 | ' |
315 | ||
d4e98b58 | 316 | test_expect_success 'diff --submodule with merge conflict in .gitmodules' ' |
44ca0c8e HV |
317 | ( |
318 | cd super && | |
319 | git diff --submodule >../diff_submodule_actual 2>&1 | |
320 | ) && | |
66b6d43c | 321 | sanitize_diff diff_submodule_actual >diff_sanitized && |
322 | test_cmp diff_submodule_expect diff_sanitized | |
44ca0c8e HV |
323 | ' |
324 | ||
dd6962dd SB |
325 | # We'll setup different cases for further testing: |
326 | # sub1 will contain a nested submodule, | |
327 | # sub2 will have an untracked file | |
328 | # sub3 will have an untracked repository | |
329 | test_expect_success 'setup superproject with untracked file in nested submodule' ' | |
330 | ( | |
331 | cd super && | |
332 | git clean -dfx && | |
23dd8f5b AO |
333 | git rm .gitmodules && |
334 | git commit -m "remove .gitmodules" && | |
dd6962dd SB |
335 | git submodule add -f ./sub1 && |
336 | git submodule add -f ./sub2 && | |
337 | git submodule add -f ./sub1 sub3 && | |
338 | git commit -a -m "messy merge in superproject" && | |
339 | ( | |
340 | cd sub1 && | |
341 | git submodule add ../sub2 && | |
342 | git commit -a -m "add sub2 to sub1" | |
343 | ) && | |
344 | git add sub1 && | |
345 | git commit -a -m "update sub1 to contain nested sub" | |
346 | ) && | |
347 | echo content >super/sub1/sub2/file && | |
348 | echo content >super/sub2/file && | |
349 | git -C super/sub3 clone ../../sub2 untracked_repository | |
350 | ' | |
351 | ||
352 | test_expect_success 'status with untracked file in nested submodule (porcelain)' ' | |
353 | git -C super status --porcelain >output && | |
354 | diff output - <<-\EOF | |
355 | M sub1 | |
356 | M sub2 | |
357 | M sub3 | |
358 | EOF | |
359 | ' | |
360 | ||
361 | test_expect_success 'status with untracked file in nested submodule (porcelain=2)' ' | |
362 | git -C super status --porcelain=2 >output && | |
363 | sanitize_output output && | |
364 | diff output - <<-\EOF | |
40069d6e | 365 | 1 .M S..U 160000 160000 160000 HASH HASH sub1 |
dd6962dd SB |
366 | 1 .M S..U 160000 160000 160000 HASH HASH sub2 |
367 | 1 .M S..U 160000 160000 160000 HASH HASH sub3 | |
368 | EOF | |
369 | ' | |
370 | ||
371 | test_expect_success 'status with untracked file in nested submodule (short)' ' | |
372 | git -C super status --short >output && | |
373 | diff output - <<-\EOF | |
40069d6e | 374 | ? sub1 |
dd6962dd SB |
375 | ? sub2 |
376 | ? sub3 | |
377 | EOF | |
378 | ' | |
379 | ||
380 | test_expect_success 'setup superproject with modified file in nested submodule' ' | |
381 | git -C super/sub1/sub2 add file && | |
382 | git -C super/sub2 add file | |
383 | ' | |
384 | ||
385 | test_expect_success 'status with added file in nested submodule (porcelain)' ' | |
386 | git -C super status --porcelain >output && | |
387 | diff output - <<-\EOF | |
388 | M sub1 | |
389 | M sub2 | |
390 | M sub3 | |
391 | EOF | |
392 | ' | |
393 | ||
394 | test_expect_success 'status with added file in nested submodule (porcelain=2)' ' | |
395 | git -C super status --porcelain=2 >output && | |
396 | sanitize_output output && | |
397 | diff output - <<-\EOF | |
398 | 1 .M S.M. 160000 160000 160000 HASH HASH sub1 | |
399 | 1 .M S.M. 160000 160000 160000 HASH HASH sub2 | |
400 | 1 .M S..U 160000 160000 160000 HASH HASH sub3 | |
401 | EOF | |
402 | ' | |
403 | ||
404 | test_expect_success 'status with added file in nested submodule (short)' ' | |
405 | git -C super status --short >output && | |
406 | diff output - <<-\EOF | |
407 | m sub1 | |
408 | m sub2 | |
409 | ? sub3 | |
410 | EOF | |
411 | ' | |
412 | ||
27bfd950 | 413 | test_done |