3 test_description
='git status for submodule'
5 TEST_PASSES_SANITIZE_LEAK
=true
8 test_create_repo_with_commit
() {
9 test_create_repo
"$1" &&
14 git commit
-m " Add bar" &&
17 git commit
-m " Add foo"
22 sed -e "s/$OID_REGEX/HASH/" -e "s/$OID_REGEX/HASH/" output
>output2
&&
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' '
40 test_grep "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_grep "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 &&
52 test_grep "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 &&
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 &&
73 test_expect_success
'status with added file in submodule' '
74 (cd sub && git reset --hard && echo >foo && git add foo) &&
76 test_grep "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 &&
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 &&
95 test_expect_success
'status with untracked file in submodule' '
96 (cd sub && git reset --hard) &&
97 echo "content" >sub/new-file &&
99 test_grep "modified: sub (untracked content)" output
102 test_expect_success
'status -uno with untracked file in submodule' '
103 git status -uno >output &&
104 test_grep "^nothing to commit" output
107 test_expect_success
'status with untracked file in submodule (porcelain)' '
108 git status --porcelain >output &&
109 diff output - <<-\EOF
114 test_expect_success
'status with untracked file in submodule (short)' '
115 git status --short >output &&
116 diff output - <<-\EOF
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_grep "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
137 test_expect_success
'status with modified file in modified submodule' '
138 (cd sub && git reset --hard) &&
140 (cd sub && echo "next change" >foo && git commit -m "next change" foo) &&
141 echo "changed" >sub/foo &&
142 git status >output &&
143 test_grep "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
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_grep "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
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_grep "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
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_grep "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
199 test_expect_success
'setup .git file for sub' '
202 REAL="$(pwd)/../.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_grep "modified: sub (new commits, modified content)" output
215 test_expect_success
'status with a lot of untracked files in the submodule' '
219 while test $i -lt 1024
222 i=$(( $i + 1 )) || exit 1
225 git status --porcelain sub 2>err.actual &&
226 test_must_be_empty err.actual &&
230 test_expect_success
'rm submodule contents' '
235 test_expect_success
'status clean (empty submodule dir)' '
236 git status >output &&
237 test_grep "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_grep "nothing to commit" output
245 cat >status_expect
<<\EOF
250 test_expect_success
'status with merge conflict in .gitmodules' '
252 test_create_repo_with_commit sub1 &&
254 test_create_repo_with_commit sub2 &&
255 test_config_global protocol.file.allow always &&
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
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
280 @@@
-1,3 -1,3 +1,9 @@@
292 cat >diff_submodule_expect <<\EOF
293 diff --cc .gitmodules
296 @@@ -1,3 -1,3 +1,9 @@@
308 test_expect_success 'diff with merge conflict in .gitmodules' '
311 git diff >../diff_actual 2>&1
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' '
320 git diff --submodule >../diff_submodule_actual 2>&1
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 &&
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" &&
343 git submodule add ../sub2 &&
344 git commit -a -m "add sub2 to sub1"
347 git commit -a -m "update sub1 to contain nested sub"
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
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
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
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