ident: don't consider '.' a crud
[git/gitster.git] / t / t7506-status-submodule.sh
blobd050091345b3929dc8e578409d45069b932c9733
1 #!/bin/sh
3 test_description='git status for submodule'
5 TEST_PASSES_SANITIZE_LEAK=true
6 . ./test-lib.sh
8 test_create_repo_with_commit () {
9 test_create_repo "$1" &&
11 cd "$1" &&
12 : >bar &&
13 git add bar &&
14 git commit -m " Add bar" &&
15 : >foo &&
16 git add foo &&
17 git commit -m " Add foo"
21 sanitize_output () {
22 sed -e "s/$OID_REGEX/HASH/" -e "s/$OID_REGEX/HASH/" output >output2 &&
23 mv output2 output
26 sanitize_diff () {
27 sed -e "/^index [0-9a-f,]*\.\.[0-9a-f]*/d" "$1"
31 test_expect_success 'setup' '
32 test_create_repo_with_commit sub &&
33 echo output > .gitignore &&
34 git add sub .gitignore &&
35 git commit -m "Add submodule sub"
38 test_expect_success 'status clean' '
39 git status >output &&
40 test_i18ngrep "nothing to commit" output
43 test_expect_success 'commit --dry-run -a clean' '
44 test_must_fail git commit --dry-run -a >output &&
45 test_i18ngrep "nothing to commit" output
48 test_expect_success 'status with modified file in submodule' '
49 (cd sub && git reset --hard) &&
50 echo "changed" >sub/foo &&
51 git status >output &&
52 test_i18ngrep "modified: sub (modified content)" output
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
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
73 test_expect_success 'status with added file in submodule' '
74 (cd sub && git reset --hard && echo >foo && git add foo) &&
75 git status >output &&
76 test_i18ngrep "modified: sub (modified content)" output
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
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
95 test_expect_success 'status with untracked file in submodule' '
96 (cd sub && git reset --hard) &&
97 echo "content" >sub/new-file &&
98 git status >output &&
99 test_i18ngrep "modified: sub (untracked content)" output
102 test_expect_success 'status -uno with untracked file in submodule' '
103 git status -uno >output &&
104 test_i18ngrep "^nothing to commit" output
107 test_expect_success 'status with untracked file in submodule (porcelain)' '
108 git status --porcelain >output &&
109 diff output - <<-\EOF
110 M sub
114 test_expect_success 'status with untracked file in submodule (short)' '
115 git status --short >output &&
116 diff output - <<-\EOF
117 ? sub
121 test_expect_success 'status with added and untracked file in submodule' '
122 (cd sub && git reset --hard && echo >foo && git add foo) &&
123 echo "content" >sub/new-file &&
124 git status >output &&
125 test_i18ngrep "modified: sub (modified content, untracked content)" output
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
137 test_expect_success 'status with modified file in modified submodule' '
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 &&
143 test_i18ngrep "modified: sub (new commits, modified content)" output
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
155 test_expect_success 'status with added file in modified submodule' '
156 (cd sub && git reset --hard && echo >foo && git add foo) &&
157 git status >output &&
158 test_i18ngrep "modified: sub (new commits, modified content)" output
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
169 test_expect_success 'status with untracked file in modified submodule' '
170 (cd sub && git reset --hard) &&
171 echo "content" >sub/new-file &&
172 git status >output &&
173 test_i18ngrep "modified: sub (new commits, untracked content)" output
176 test_expect_success 'status with untracked file in modified submodule (porcelain)' '
177 git status --porcelain >output &&
178 diff output - <<-\EOF
179 M sub
183 test_expect_success 'status with added and untracked file in modified submodule' '
184 (cd sub && git reset --hard && echo >foo && git add foo) &&
185 echo "content" >sub/new-file &&
186 git status >output &&
187 test_i18ngrep "modified: sub (new commits, modified content, untracked content)" output
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
199 test_expect_success 'setup .git file for sub' '
200 (cd sub &&
201 rm -f new-file &&
202 REAL="$(pwd)/../.real" &&
203 mv .git "$REAL" &&
204 echo "gitdir: $REAL" >.git) &&
205 echo .real >>.gitignore &&
206 git commit -m "added .real to .gitignore" .gitignore
209 test_expect_success 'status with added file in modified submodule with .git file' '
210 (cd sub && git reset --hard && echo >foo && git add foo) &&
211 git status >output &&
212 test_i18ngrep "modified: sub (new commits, modified content)" output
215 test_expect_success 'status with a lot of untracked files in the submodule' '
217 cd sub &&
218 i=0 &&
219 while test $i -lt 1024
221 >some-file-$i &&
222 i=$(( $i + 1 )) || exit 1
223 done
224 ) &&
225 git status --porcelain sub 2>err.actual &&
226 test_must_be_empty err.actual &&
227 rm err.actual
230 test_expect_success 'rm submodule contents' '
231 rm -rf sub &&
232 mkdir sub
235 test_expect_success 'status clean (empty submodule dir)' '
236 git status >output &&
237 test_i18ngrep "nothing to commit" output
240 test_expect_success 'status -a clean (empty submodule dir)' '
241 test_must_fail git commit --dry-run -a >output &&
242 test_i18ngrep "nothing to commit" output
245 cat >status_expect <<\EOF
246 AA .gitmodules
247 A sub1
250 test_expect_success 'status with merge conflict in .gitmodules' '
251 git clone . super &&
252 test_create_repo_with_commit sub1 &&
253 test_tick &&
254 test_create_repo_with_commit sub2 &&
255 test_config_global protocol.file.allow always &&
257 cd super &&
258 prev=$(git rev-parse HEAD) &&
259 git checkout -b add_sub1 &&
260 git submodule add ../sub1 &&
261 git commit -m "add sub1" &&
262 git checkout -b add_sub2 $prev &&
263 git submodule add ../sub2 &&
264 git commit -m "add sub2" &&
265 git checkout -b merge_conflict_gitmodules &&
266 test_must_fail git merge add_sub1 &&
267 git status -s >../status_actual 2>&1
268 ) &&
269 test_cmp status_actual status_expect
272 sha1_merge_sub1=$(cd sub1 && git rev-parse HEAD)
273 sha1_merge_sub2=$(cd sub2 && git rev-parse HEAD)
274 short_sha1_merge_sub1=$(cd sub1 && git rev-parse --short HEAD)
275 short_sha1_merge_sub2=$(cd sub2 && git rev-parse --short HEAD)
276 cat >diff_expect <<\EOF
277 diff --cc .gitmodules
278 --- a/.gitmodules
279 +++ b/.gitmodules
280 @@@ -1,3 -1,3 +1,9 @@@
281 ++<<<<<<< HEAD
282 +[submodule "sub2"]
283 + path = sub2
284 + url = ../sub2
285 ++=======
286 + [submodule "sub1"]
287 + path = sub1
288 + url = ../sub1
289 ++>>>>>>> add_sub1
292 cat >diff_submodule_expect <<\EOF
293 diff --cc .gitmodules
294 --- a/.gitmodules
295 +++ b/.gitmodules
296 @@@ -1,3 -1,3 +1,9 @@@
297 ++<<<<<<< HEAD
298 +[submodule "sub2"]
299 + path = sub2
300 + url = ../sub2
301 ++=======
302 + [submodule "sub1"]
303 + path = sub1
304 + url = ../sub1
305 ++>>>>>>> add_sub1
308 test_expect_success 'diff with merge conflict in .gitmodules' '
310 cd super &&
311 git diff >../diff_actual 2>&1
312 ) &&
313 sanitize_diff diff_actual >diff_sanitized &&
314 test_cmp diff_expect diff_sanitized
317 test_expect_success 'diff --submodule with merge conflict in .gitmodules' '
319 cd super &&
320 git diff --submodule >../diff_submodule_actual 2>&1
321 ) &&
322 sanitize_diff diff_submodule_actual >diff_sanitized &&
323 test_cmp diff_submodule_expect diff_sanitized
326 # We'll setup different cases for further testing:
327 # sub1 will contain a nested submodule,
328 # sub2 will have an untracked file
329 # sub3 will have an untracked repository
330 test_expect_success 'setup superproject with untracked file in nested submodule' '
331 test_config_global protocol.file.allow always &&
333 cd super &&
334 git clean -dfx &&
335 git rm .gitmodules &&
336 git commit -m "remove .gitmodules" &&
337 git submodule add -f ./sub1 &&
338 git submodule add -f ./sub2 &&
339 git submodule add -f ./sub1 sub3 &&
340 git commit -a -m "messy merge in superproject" &&
342 cd sub1 &&
343 git submodule add ../sub2 &&
344 git commit -a -m "add sub2 to sub1"
345 ) &&
346 git add sub1 &&
347 git commit -a -m "update sub1 to contain nested sub"
348 ) &&
349 echo content >super/sub1/sub2/file &&
350 echo content >super/sub2/file &&
351 git -C super/sub3 clone ../../sub2 untracked_repository
354 test_expect_success 'status with untracked file in nested submodule (porcelain)' '
355 git -C super status --porcelain >output &&
356 diff output - <<-\EOF
357 M sub1
358 M sub2
359 M sub3
363 test_expect_success 'status with untracked file in nested submodule (porcelain=2)' '
364 git -C super status --porcelain=2 >output &&
365 sanitize_output output &&
366 diff output - <<-\EOF
367 1 .M S..U 160000 160000 160000 HASH HASH sub1
368 1 .M S..U 160000 160000 160000 HASH HASH sub2
369 1 .M S..U 160000 160000 160000 HASH HASH sub3
373 test_expect_success 'status with untracked file in nested submodule (short)' '
374 git -C super status --short >output &&
375 diff output - <<-\EOF
376 ? sub1
377 ? sub2
378 ? sub3
382 test_expect_success 'setup superproject with modified file in nested submodule' '
383 git -C super/sub1/sub2 add file &&
384 git -C super/sub2 add file
387 test_expect_success 'status with added file in nested submodule (porcelain)' '
388 git -C super status --porcelain >output &&
389 diff output - <<-\EOF
390 M sub1
391 M sub2
392 M sub3
396 test_expect_success 'status with added file in nested submodule (porcelain=2)' '
397 git -C super status --porcelain=2 >output &&
398 sanitize_output output &&
399 diff output - <<-\EOF
400 1 .M S.M. 160000 160000 160000 HASH HASH sub1
401 1 .M S.M. 160000 160000 160000 HASH HASH sub2
402 1 .M S..U 160000 160000 160000 HASH HASH sub3
406 test_expect_success 'status with added file in nested submodule (short)' '
407 git -C super status --short >output &&
408 diff output - <<-\EOF
409 m sub1
410 m sub2
411 ? sub3
415 test_done