3 test_description='git status for submodule'
7 test_create_repo_with_commit () {
8 test_create_repo "$1" &&
13 git commit -m " Add bar" &&
16 git commit -m " Add foo"
21 sed -e "s/$OID_REGEX/HASH/" -e "s/$OID_REGEX/HASH/" output >output2 &&
26 sed -e "/^index [0-9a-f,]*\.\.[0-9a-f]*/d" "$1"
30 test_expect_success 'setup' '
31 test_create_repo_with_commit sub &&
32 echo output > .gitignore &&
33 git add sub .gitignore &&
34 git commit -m "Add submodule sub"
37 test_expect_success 'status clean' '
39 test_i18ngrep "nothing to commit" output
42 test_expect_success 'commit --dry-run -a clean' '
43 test_must_fail git commit --dry-run -a >output &&
44 test_i18ngrep "nothing to commit" output
47 test_expect_success 'status with modified file in submodule' '
48 (cd sub && git reset --hard) &&
49 echo "changed" >sub/foo &&
51 test_i18ngrep "modified: sub (modified content)" output
54 test_expect_success 'status with modified file in submodule (porcelain)' '
55 (cd sub && git reset --hard) &&
56 echo "changed" >sub/foo &&
57 git status --porcelain >output &&
63 test_expect_success 'status with modified file in submodule (short)' '
64 (cd sub && git reset --hard) &&
65 echo "changed" >sub/foo &&
66 git status --short >output &&
72 test_expect_success 'status with added file in submodule' '
73 (cd sub && git reset --hard && echo >foo && git add foo) &&
75 test_i18ngrep "modified: sub (modified content)" output
78 test_expect_success 'status with added file in submodule (porcelain)' '
79 (cd sub && git reset --hard && echo >foo && git add foo) &&
80 git status --porcelain >output &&
86 test_expect_success 'status with added file in submodule (short)' '
87 (cd sub && git reset --hard && echo >foo && git add foo) &&
88 git status --short >output &&
94 test_expect_success 'status with untracked file in submodule' '
95 (cd sub && git reset --hard) &&
96 echo "content" >sub/new-file &&
98 test_i18ngrep "modified: sub (untracked content)" output
101 test_expect_success 'status -uno with untracked file in submodule' '
102 git status -uno >output &&
103 test_i18ngrep "^nothing to commit" output
106 test_expect_success 'status with untracked file in submodule (porcelain)' '
107 git status --porcelain >output &&
108 diff output - <<-\EOF
113 test_expect_success 'status with untracked file in submodule (short)' '
114 git status --short >output &&
115 diff output - <<-\EOF
120 test_expect_success 'status with added and untracked file in submodule' '
121 (cd sub && git reset --hard && echo >foo && git add foo) &&
122 echo "content" >sub/new-file &&
123 git status >output &&
124 test_i18ngrep "modified: sub (modified content, untracked content)" output
127 test_expect_success 'status with added and untracked file in submodule (porcelain)' '
128 (cd sub && git reset --hard && echo >foo && git add foo) &&
129 echo "content" >sub/new-file &&
130 git status --porcelain >output &&
131 diff output - <<-\EOF
136 test_expect_success 'status with modified file in modified submodule' '
137 (cd sub && git reset --hard) &&
139 (cd sub && echo "next change" >foo && git commit -m "next change" foo) &&
140 echo "changed" >sub/foo &&
141 git status >output &&
142 test_i18ngrep "modified: sub (new commits, modified content)" output
145 test_expect_success 'status with modified file in modified submodule (porcelain)' '
146 (cd sub && git reset --hard) &&
147 echo "changed" >sub/foo &&
148 git status --porcelain >output &&
149 diff output - <<-\EOF
154 test_expect_success 'status with added file in modified submodule' '
155 (cd sub && git reset --hard && echo >foo && git add foo) &&
156 git status >output &&
157 test_i18ngrep "modified: sub (new commits, modified content)" output
160 test_expect_success 'status with added file in modified submodule (porcelain)' '
161 (cd sub && git reset --hard && echo >foo && git add foo) &&
162 git status --porcelain >output &&
163 diff output - <<-\EOF
168 test_expect_success 'status with untracked file in modified submodule' '
169 (cd sub && git reset --hard) &&
170 echo "content" >sub/new-file &&
171 git status >output &&
172 test_i18ngrep "modified: sub (new commits, untracked content)" output
175 test_expect_success 'status with untracked file in modified submodule (porcelain)' '
176 git status --porcelain >output &&
177 diff output - <<-\EOF
182 test_expect_success 'status with added and untracked file in modified submodule' '
183 (cd sub && git reset --hard && echo >foo && git add foo) &&
184 echo "content" >sub/new-file &&
185 git status >output &&
186 test_i18ngrep "modified: sub (new commits, modified content, untracked content)" output
189 test_expect_success 'status with added and untracked file in modified submodule (porcelain)' '
190 (cd sub && git reset --hard && echo >foo && git add foo) &&
191 echo "content" >sub/new-file &&
192 git status --porcelain >output &&
193 diff output - <<-\EOF
198 test_expect_success 'setup .git file for sub' '
201 REAL="$(pwd)/../.real" &&
203 echo "gitdir: $REAL" >.git) &&
204 echo .real >>.gitignore &&
205 git commit -m "added .real to .gitignore" .gitignore
208 test_expect_success 'status with added file in modified submodule with .git file' '
209 (cd sub && git reset --hard && echo >foo && git add foo) &&
210 git status >output &&
211 test_i18ngrep "modified: sub (new commits, modified content)" output
214 test_expect_success 'status with a lot of untracked files in the submodule' '
218 while test $i -lt 1024
221 i=$(( $i + 1 )) || exit 1
224 git status --porcelain sub 2>err.actual &&
225 test_must_be_empty err.actual &&
229 test_expect_success 'rm submodule contents' '
234 test_expect_success 'status clean (empty submodule dir)' '
235 git status >output &&
236 test_i18ngrep "nothing to commit" output
239 test_expect_success 'status -a clean (empty submodule dir)' '
240 test_must_fail git commit --dry-run -a >output &&
241 test_i18ngrep "nothing to commit" output
244 cat >status_expect <<\EOF
249 test_expect_success 'status with merge conflict in .gitmodules' '
251 test_create_repo_with_commit sub1 &&
253 test_create_repo_with_commit sub2 &&
256 prev=$(git rev-parse HEAD) &&
257 git checkout -b add_sub1 &&
258 git submodule add ../sub1 &&
259 git commit -m "add sub1" &&
260 git checkout -b add_sub2 $prev &&
261 git submodule add ../sub2 &&
262 git commit -m "add sub2" &&
263 git checkout -b merge_conflict_gitmodules &&
264 test_must_fail git merge add_sub1 &&
265 git status -s >../status_actual 2>&1
267 test_cmp status_actual status_expect
270 sha1_merge_sub1=$(cd sub1 && git rev-parse HEAD)
271 sha1_merge_sub2=$(cd sub2 && git rev-parse HEAD)
272 short_sha1_merge_sub1=$(cd sub1 && git rev-parse --short HEAD)
273 short_sha1_merge_sub2=$(cd sub2 && git rev-parse --short HEAD)
274 cat >diff_expect <<\EOF
275 diff --cc .gitmodules
278 @@@ -1,3 -1,3 +1,9 @@@
290 cat >diff_submodule_expect <<\EOF
291 diff --cc .gitmodules
294 @@@ -1,3 -1,3 +1,9 @@@
306 test_expect_success 'diff with merge conflict in .gitmodules' '
309 git diff >../diff_actual 2>&1
311 sanitize_diff diff_actual >diff_sanitized &&
312 test_cmp diff_expect diff_sanitized
315 test_expect_success 'diff --submodule with merge conflict in .gitmodules' '
318 git diff --submodule >../diff_submodule_actual 2>&1
320 sanitize_diff diff_submodule_actual >diff_sanitized &&
321 test_cmp diff_submodule_expect diff_sanitized
324 # We'll setup different cases for further testing:
325 # sub1 will contain a nested submodule,
326 # sub2 will have an untracked file
327 # sub3 will have an untracked repository
328 test_expect_success 'setup superproject with untracked file in nested submodule' '
332 git rm .gitmodules &&
333 git commit -m "remove .gitmodules" &&
334 git submodule add -f ./sub1 &&
335 git submodule add -f ./sub2 &&
336 git submodule add -f ./sub1 sub3 &&
337 git commit -a -m "messy merge in superproject" &&
340 git submodule add ../sub2 &&
341 git commit -a -m "add sub2 to sub1"
344 git commit -a -m "update sub1 to contain nested sub"
346 echo content >super/sub1/sub2/file &&
347 echo content >super/sub2/file &&
348 git -C super/sub3 clone ../../sub2 untracked_repository
351 test_expect_success 'status with untracked file in nested submodule (porcelain)' '
352 git -C super status --porcelain >output &&
353 diff output - <<-\EOF
360 test_expect_success 'status with untracked file in nested submodule (porcelain=2)' '
361 git -C super status --porcelain=2 >output &&
362 sanitize_output output &&
363 diff output - <<-\EOF
364 1 .M S..U 160000 160000 160000 HASH HASH sub1
365 1 .M S..U 160000 160000 160000 HASH HASH sub2
366 1 .M S..U 160000 160000 160000 HASH HASH sub3
370 test_expect_success 'status with untracked file in nested submodule (short)' '
371 git -C super status --short >output &&
372 diff output - <<-\EOF
379 test_expect_success 'setup superproject with modified file in nested submodule' '
380 git -C super/sub1/sub2 add file &&
381 git -C super/sub2 add file
384 test_expect_success 'status with added file in nested submodule (porcelain)' '
385 git -C super status --porcelain >output &&
386 diff output - <<-\EOF
393 test_expect_success 'status with added file in nested submodule (porcelain=2)' '
394 git -C super status --porcelain=2 >output &&
395 sanitize_output output &&
396 diff output - <<-\EOF
397 1 .M S.M. 160000 160000 160000 HASH HASH sub1
398 1 .M S.M. 160000 160000 160000 HASH HASH sub2
399 1 .M S..U 160000 160000 160000 HASH HASH sub3
403 test_expect_success 'status with added file in nested submodule (short)' '
404 git -C super status --short >output &&
405 diff output - <<-\EOF