3 test_description='git status --porcelain=v2
5 This test exercises porcelain V2 output for git status.'
11 test_expect_success setup '
13 git config core.autocrlf false &&
18 echo a >dir1/file_a &&
22 test_expect_success 'before initial commit, nothing added, only untracked' '
24 # branch.oid (initial)
34 git status --porcelain=v2 --branch --untracked-files=normal >actual &&
35 test_cmp expect actual
38 test_expect_success 'before initial commit, things added' '
39 git add file_x file_y file_z dir1 &&
40 OID_A=$(git hash-object -t blob -- dir1/file_a) &&
41 OID_B=$(git hash-object -t blob -- dir1/file_b) &&
42 OID_X=$(git hash-object -t blob -- file_x) &&
43 OID_Y=$(git hash-object -t blob -- file_y) &&
44 OID_Z=$(git hash-object -t blob -- file_z) &&
47 # branch.oid (initial)
49 1 A. N... 000000 100644 100644 $_z40 $OID_A dir1/file_a
50 1 A. N... 000000 100644 100644 $_z40 $OID_B dir1/file_b
51 1 A. N... 000000 100644 100644 $_z40 $OID_X file_x
52 1 A. N... 000000 100644 100644 $_z40 $OID_Y file_y
53 1 A. N... 000000 100644 100644 $_z40 $OID_Z file_z
58 git status --porcelain=v2 --branch --untracked-files=all >actual &&
59 test_cmp expect actual
62 test_expect_success 'before initial commit, things added (-z)' '
63 lf_to_nul >expect <<-EOF &&
64 # branch.oid (initial)
66 1 A. N... 000000 100644 100644 $_z40 $OID_A dir1/file_a
67 1 A. N... 000000 100644 100644 $_z40 $OID_B dir1/file_b
68 1 A. N... 000000 100644 100644 $_z40 $OID_X file_x
69 1 A. N... 000000 100644 100644 $_z40 $OID_Y file_y
70 1 A. N... 000000 100644 100644 $_z40 $OID_Z file_z
75 git status -z --porcelain=v2 --branch --untracked-files=all >actual &&
76 test_cmp expect actual
79 test_expect_success 'make first commit, comfirm HEAD oid and branch' '
80 git commit -m initial &&
81 H0=$(git rev-parse HEAD) &&
89 git status --porcelain=v2 --branch --untracked-files=all >actual &&
90 test_cmp expect actual
93 test_expect_success 'after first commit, create unstaged changes' '
95 OID_X1=$(git hash-object -t blob -- file_x) &&
97 H0=$(git rev-parse HEAD) &&
102 1 .M N... 100644 100644 100644 $OID_X $OID_X file_x
103 1 .D N... 100644 100644 000000 $OID_Z $OID_Z file_z
108 git status --porcelain=v2 --branch --untracked-files=all >actual &&
109 test_cmp expect actual
112 test_expect_success 'after first commit but omit untracked files and branch' '
113 cat >expect <<-EOF &&
114 1 .M N... 100644 100644 100644 $OID_X $OID_X file_x
115 1 .D N... 100644 100644 000000 $OID_Z $OID_Z file_z
118 git status --porcelain=v2 --untracked-files=no >actual &&
119 test_cmp expect actual
122 test_expect_success 'after first commit, stage existing changes' '
125 H0=$(git rev-parse HEAD) &&
127 cat >expect <<-EOF &&
130 1 M. N... 100644 100644 100644 $OID_X $OID_X1 file_x
131 1 D. N... 100644 000000 000000 $OID_Z $_z40 file_z
136 git status --porcelain=v2 --branch --untracked-files=all >actual &&
137 test_cmp expect actual
140 test_expect_success 'rename causes 2 path lines' '
141 git mv file_y renamed_y &&
142 H0=$(git rev-parse HEAD) &&
144 q_to_tab >expect <<-EOF &&
147 1 M. N... 100644 100644 100644 $OID_X $OID_X1 file_x
148 1 D. N... 100644 000000 000000 $OID_Z $_z40 file_z
149 2 R. N... 100644 100644 100644 $OID_Y $OID_Y R100 renamed_yQfile_y
154 git status --porcelain=v2 --branch --untracked-files=all >actual &&
155 test_cmp expect actual
158 test_expect_success 'rename causes 2 path lines (-z)' '
159 H0=$(git rev-parse HEAD) &&
161 ## Lines use NUL path separator and line terminator, so double transform here.
162 q_to_nul <<-EOF | lf_to_nul >expect &&
165 1 M. N... 100644 100644 100644 $OID_X $OID_X1 file_x
166 1 D. N... 100644 000000 000000 $OID_Z $_z40 file_z
167 2 R. N... 100644 100644 100644 $OID_Y $OID_Y R100 renamed_yQfile_y
172 git status --porcelain=v2 --branch --untracked-files=all -z >actual &&
173 test_cmp expect actual
176 test_expect_success 'make second commit, confirm clean and new HEAD oid' '
177 git commit -m second &&
178 H1=$(git rev-parse HEAD) &&
180 cat >expect <<-EOF &&
187 git status --porcelain=v2 --branch --untracked-files=all >actual &&
188 test_cmp expect actual
191 test_expect_success 'confirm ignored files are not printed' '
192 test_when_finished "rm -f x.ign .gitignore" &&
193 echo x.ign >.gitignore &&
194 echo "ignore me" >x.ign &&
196 cat >expect <<-EOF &&
202 git status --porcelain=v2 --untracked-files=all >actual &&
203 test_cmp expect actual
206 test_expect_success 'ignored files are printed with --ignored' '
207 test_when_finished "rm -f x.ign .gitignore" &&
208 echo x.ign >.gitignore &&
209 echo "ignore me" >x.ign &&
211 cat >expect <<-EOF &&
218 git status --porcelain=v2 --ignored --untracked-files=all >actual &&
219 test_cmp expect actual
222 test_expect_success 'create and commit permanent ignore file' '
223 cat >.gitignore <<-EOF &&
228 git add .gitignore &&
229 git commit -m ignore_trash &&
230 H1=$(git rev-parse HEAD) &&
232 cat >expect <<-EOF &&
237 git status --porcelain=v2 --branch >actual &&
238 test_cmp expect actual
241 test_expect_success 'verify --intent-to-add output' '
242 test_when_finished "git rm -f intent1.add intent2.add" &&
244 echo test >intent2.add &&
246 git add --intent-to-add intent1.add intent2.add &&
248 cat >expect <<-EOF &&
249 1 AM N... 000000 100644 100644 $_z40 $EMPTY_BLOB intent1.add
250 1 AM N... 000000 100644 100644 $_z40 $EMPTY_BLOB intent2.add
253 git status --porcelain=v2 >actual &&
254 test_cmp expect actual
257 test_expect_success 'verify AA (add-add) conflict' '
258 test_when_finished "git reset --hard" &&
260 git branch AA_A master &&
262 echo "Branch AA_A" >conflict.txt &&
263 OID_AA_A=$(git hash-object -t blob -- conflict.txt) &&
264 git add conflict.txt &&
265 git commit -m "branch aa_a" &&
267 git branch AA_B master &&
269 echo "Branch AA_B" >conflict.txt &&
270 OID_AA_B=$(git hash-object -t blob -- conflict.txt) &&
271 git add conflict.txt &&
272 git commit -m "branch aa_b" &&
274 git branch AA_M AA_B &&
276 test_must_fail git merge AA_A &&
278 HM=$(git rev-parse HEAD) &&
280 cat >expect <<-EOF &&
283 u AA N... 000000 100644 100644 100644 $_z40 $OID_AA_B $OID_AA_A conflict.txt
286 git status --porcelain=v2 --branch --untracked-files=all >actual &&
287 test_cmp expect actual
290 test_expect_success 'verify UU (edit-edit) conflict' '
291 test_when_finished "git reset --hard" &&
293 git branch UU_ANC master &&
294 git checkout UU_ANC &&
295 echo "Ancestor" >conflict.txt &&
296 OID_UU_ANC=$(git hash-object -t blob -- conflict.txt) &&
297 git add conflict.txt &&
298 git commit -m "UU_ANC" &&
300 git branch UU_A UU_ANC &&
302 echo "Branch UU_A" >conflict.txt &&
303 OID_UU_A=$(git hash-object -t blob -- conflict.txt) &&
304 git add conflict.txt &&
305 git commit -m "branch uu_a" &&
307 git branch UU_B UU_ANC &&
309 echo "Branch UU_B" >conflict.txt &&
310 OID_UU_B=$(git hash-object -t blob -- conflict.txt) &&
311 git add conflict.txt &&
312 git commit -m "branch uu_b" &&
314 git branch UU_M UU_B &&
316 test_must_fail git merge UU_A &&
318 HM=$(git rev-parse HEAD) &&
320 cat >expect <<-EOF &&
323 u UU N... 100644 100644 100644 100644 $OID_UU_ANC $OID_UU_B $OID_UU_A conflict.txt
326 git status --porcelain=v2 --branch --untracked-files=all >actual &&
327 test_cmp expect actual
330 test_expect_success 'verify upstream fields in branch header' '
331 git checkout master &&
332 test_when_finished "rm -rf sub_repo" &&
333 git clone . sub_repo &&
335 ## Confirm local master tracks remote master.
337 HUF=$(git rev-parse HEAD) &&
339 cat >expect <<-EOF &&
342 # branch.upstream origin/master
346 git status --porcelain=v2 --branch --untracked-files=all >actual &&
347 test_cmp expect actual &&
349 ## Test ahead/behind.
350 echo xyz >file_xyz &&
354 HUF=$(git rev-parse HEAD) &&
356 cat >expect <<-EOF &&
359 # branch.upstream origin/master
363 git status --porcelain=v2 --branch --untracked-files=all >actual &&
364 test_cmp expect actual &&
366 ## Repeat the above but without --branch.
367 cat >expect <<-EOF &&
370 git status --porcelain=v2 --untracked-files=all >actual &&
371 test_cmp expect actual &&
373 ## Test upstream-gone case. Fake this by pointing origin/master at
374 ## a non-existing commit.
375 OLD=$(git rev-parse origin/master) &&
377 mv .git/packed-refs .git/old-packed-refs &&
378 sed "s/$OLD/$NEW/g" <.git/old-packed-refs >.git/packed-refs &&
380 HUF=$(git rev-parse HEAD) &&
382 cat >expect <<-EOF &&
385 # branch.upstream origin/master
388 git status --porcelain=v2 --branch --untracked-files=all >actual &&
389 test_cmp expect actual
393 test_expect_success 'create and add submodule, submodule appears clean (A. S...)' '
394 git checkout master &&
395 git clone . sub_repo &&
396 git clone . super_repo &&
398 git submodule add ../sub_repo sub1 &&
400 ## Confirm stage/add of clean submodule.
401 HMOD=$(git hash-object -t blob -- .gitmodules) &&
402 HSUP=$(git rev-parse HEAD) &&
405 cat >expect <<-EOF &&
408 # branch.upstream origin/master
410 1 A. N... 000000 100644 100644 $_z40 $HMOD .gitmodules
411 1 A. S... 000000 160000 160000 $_z40 $HSUB sub1
414 git status --porcelain=v2 --branch --untracked-files=all >actual &&
415 test_cmp expect actual
419 test_expect_success 'untracked changes in added submodule (AM S..U)' '
421 ## create untracked file in the submodule.
423 echo "xxxx" >file_in_sub
426 HMOD=$(git hash-object -t blob -- .gitmodules) &&
427 HSUP=$(git rev-parse HEAD) &&
430 cat >expect <<-EOF &&
433 # branch.upstream origin/master
435 1 A. N... 000000 100644 100644 $_z40 $HMOD .gitmodules
436 1 AM S..U 000000 160000 160000 $_z40 $HSUB sub1
439 git status --porcelain=v2 --branch --untracked-files=all >actual &&
440 test_cmp expect actual
444 test_expect_success 'staged changes in added submodule (AM S.M.)' '
446 ## stage the changes in the submodule.
451 HMOD=$(git hash-object -t blob -- .gitmodules) &&
452 HSUP=$(git rev-parse HEAD) &&
455 cat >expect <<-EOF &&
458 # branch.upstream origin/master
460 1 A. N... 000000 100644 100644 $_z40 $HMOD .gitmodules
461 1 AM S.M. 000000 160000 160000 $_z40 $HSUB sub1
464 git status --porcelain=v2 --branch --untracked-files=all >actual &&
465 test_cmp expect actual
469 test_expect_success 'staged and unstaged changes in added (AM S.M.)' '
472 ## make additional unstaged changes (on the same file) in the submodule.
473 ## This does not cause us to get S.MU (because the submodule does not report
474 ## a "?" line for the unstaged changes).
475 echo "more changes" >>file_in_sub
478 HMOD=$(git hash-object -t blob -- .gitmodules) &&
479 HSUP=$(git rev-parse HEAD) &&
482 cat >expect <<-EOF &&
485 # branch.upstream origin/master
487 1 A. N... 000000 100644 100644 $_z40 $HMOD .gitmodules
488 1 AM S.M. 000000 160000 160000 $_z40 $HSUB sub1
491 git status --porcelain=v2 --branch --untracked-files=all >actual &&
492 test_cmp expect actual
496 test_expect_success 'staged and untracked changes in added submodule (AM S.MU)' '
499 ## stage new changes in tracked file.
500 git add file_in_sub &&
501 ## create new untracked file.
502 echo "yyyy" >>another_file_in_sub
505 HMOD=$(git hash-object -t blob -- .gitmodules) &&
506 HSUP=$(git rev-parse HEAD) &&
509 cat >expect <<-EOF &&
512 # branch.upstream origin/master
514 1 A. N... 000000 100644 100644 $_z40 $HMOD .gitmodules
515 1 AM S.MU 000000 160000 160000 $_z40 $HSUB sub1
518 git status --porcelain=v2 --branch --untracked-files=all >actual &&
519 test_cmp expect actual
523 test_expect_success 'commit within the submodule appears as new commit in super (AM SC..)' '
526 ## Make a new commit in the submodule.
527 git add file_in_sub &&
528 rm -f another_file_in_sub &&
529 git commit -m "new commit"
532 HMOD=$(git hash-object -t blob -- .gitmodules) &&
533 HSUP=$(git rev-parse HEAD) &&
536 cat >expect <<-EOF &&
539 # branch.upstream origin/master
541 1 A. N... 000000 100644 100644 $_z40 $HMOD .gitmodules
542 1 AM SC.. 000000 160000 160000 $_z40 $HSUB sub1
545 git status --porcelain=v2 --branch --untracked-files=all >actual &&
546 test_cmp expect actual
550 test_expect_success 'stage submodule in super and commit' '
552 ## Stage the new submodule commit in the super.
554 ## Commit the super so that the sub no longer appears as added.
555 git commit -m "super commit" &&
557 HSUP=$(git rev-parse HEAD) &&
559 cat >expect <<-EOF &&
562 # branch.upstream origin/master
566 git status --porcelain=v2 --branch --untracked-files=all >actual &&
567 test_cmp expect actual
571 test_expect_success 'make unstaged changes in existing submodule (.M S.M.)' '
574 echo "zzzz" >>file_in_sub
577 HSUP=$(git rev-parse HEAD) &&
578 HSUB=$(cd sub1 && git rev-parse HEAD) &&
580 cat >expect <<-EOF &&
583 # branch.upstream origin/master
585 1 .M S.M. 160000 160000 160000 $HSUB $HSUB sub1
588 git status --porcelain=v2 --branch --untracked-files=all >actual &&
589 test_cmp expect actual