3 test_description
='git status --porcelain=v2
5 This test exercises porcelain V2 output for git status.'
7 TEST_PASSES_SANITIZE_LEAK
=true
11 test_expect_success setup
'
12 git checkout -f --orphan initial-branch &&
14 git config core.autocrlf false &&
19 echo a >dir1/file_a &&
23 test_expect_success
'before initial commit, nothing added, only untracked' '
25 # branch.oid (initial)
26 # branch.head initial-branch
35 git status --porcelain=v2 --branch --untracked-files=normal >actual &&
36 test_cmp expect actual
39 test_expect_success
'before initial commit, things added' '
40 git add file_x file_y file_z dir1 &&
41 OID_A=$(git hash-object -t blob -- dir1/file_a) &&
42 OID_B=$(git hash-object -t blob -- dir1/file_b) &&
43 OID_X=$(git hash-object -t blob -- file_x) &&
44 OID_Y=$(git hash-object -t blob -- file_y) &&
45 OID_Z=$(git hash-object -t blob -- file_z) &&
48 # branch.oid (initial)
49 # branch.head initial-branch
50 1 A. N... 000000 100644 100644 $ZERO_OID $OID_A dir1/file_a
51 1 A. N... 000000 100644 100644 $ZERO_OID $OID_B dir1/file_b
52 1 A. N... 000000 100644 100644 $ZERO_OID $OID_X file_x
53 1 A. N... 000000 100644 100644 $ZERO_OID $OID_Y file_y
54 1 A. N... 000000 100644 100644 $ZERO_OID $OID_Z file_z
59 git status --porcelain=v2 --branch --untracked-files=all >actual &&
60 test_cmp expect actual
63 test_expect_success
'before initial commit, things added (-z)' '
64 lf_to_nul >expect <<-EOF &&
65 # branch.oid (initial)
66 # branch.head initial-branch
67 1 A. N... 000000 100644 100644 $ZERO_OID $OID_A dir1/file_a
68 1 A. N... 000000 100644 100644 $ZERO_OID $OID_B dir1/file_b
69 1 A. N... 000000 100644 100644 $ZERO_OID $OID_X file_x
70 1 A. N... 000000 100644 100644 $ZERO_OID $OID_Y file_y
71 1 A. N... 000000 100644 100644 $ZERO_OID $OID_Z file_z
76 git status -z --porcelain=v2 --branch --untracked-files=all >actual &&
77 test_cmp expect actual
80 test_expect_success
'make first commit, comfirm HEAD oid and branch' '
81 git commit -m initial &&
82 H0=$(git rev-parse HEAD) &&
85 # branch.head initial-branch
90 git status --porcelain=v2 --branch --untracked-files=all >actual &&
91 test_cmp expect actual
94 test_expect_success
'after first commit, create unstaged changes' '
96 OID_X1=$(git hash-object -t blob -- file_x) &&
98 H0=$(git rev-parse HEAD) &&
100 cat >expect <<-EOF &&
102 # branch.head initial-branch
103 1 .M N... 100644 100644 100644 $OID_X $OID_X file_x
104 1 .D N... 100644 100644 000000 $OID_Z $OID_Z file_z
109 git status --porcelain=v2 --branch --untracked-files=all >actual &&
110 test_cmp expect actual
113 test_expect_success
'after first commit, stash existing changes' '
114 cat >expect <<-EOF &&
116 # branch.head initial-branch
120 test_when_finished "git stash pop && git stash pop" &&
122 git stash -- file_x &&
124 git status --porcelain=v2 --branch --show-stash --untracked-files=no >actual &&
125 test_cmp expect actual
128 test_expect_success
'after first commit but omit untracked files and branch' '
129 cat >expect <<-EOF &&
130 1 .M N... 100644 100644 100644 $OID_X $OID_X file_x
131 1 .D N... 100644 100644 000000 $OID_Z $OID_Z file_z
134 git status --porcelain=v2 --untracked-files=no >actual &&
135 test_cmp expect actual
138 test_expect_success
'after first commit, stage existing changes' '
141 H0=$(git rev-parse HEAD) &&
143 cat >expect <<-EOF &&
145 # branch.head initial-branch
146 1 M. N... 100644 100644 100644 $OID_X $OID_X1 file_x
147 1 D. N... 100644 000000 000000 $OID_Z $ZERO_OID file_z
152 git status --porcelain=v2 --branch --untracked-files=all >actual &&
153 test_cmp expect actual
156 test_expect_success
'rename causes 2 path lines' '
157 git mv file_y renamed_y &&
158 H0=$(git rev-parse HEAD) &&
160 q_to_tab >expect <<-EOF &&
162 # branch.head initial-branch
163 1 M. N... 100644 100644 100644 $OID_X $OID_X1 file_x
164 1 D. N... 100644 000000 000000 $OID_Z $ZERO_OID file_z
165 2 R. N... 100644 100644 100644 $OID_Y $OID_Y R100 renamed_yQfile_y
170 git status --porcelain=v2 --branch --untracked-files=all >actual &&
171 test_cmp expect actual
174 test_expect_success
'rename causes 2 path lines (-z)' '
175 H0=$(git rev-parse HEAD) &&
177 ## Lines use NUL path separator and line terminator, so double transform here.
178 q_to_nul <<-EOF | lf_to_nul >expect &&
180 # branch.head initial-branch
181 1 M. N... 100644 100644 100644 $OID_X $OID_X1 file_x
182 1 D. N... 100644 000000 000000 $OID_Z $ZERO_OID file_z
183 2 R. N... 100644 100644 100644 $OID_Y $OID_Y R100 renamed_yQfile_y
188 git status --porcelain=v2 --branch --untracked-files=all -z >actual &&
189 test_cmp expect actual
192 test_expect_success
'make second commit, confirm clean and new HEAD oid' '
193 git commit -m second &&
194 H1=$(git rev-parse HEAD) &&
196 cat >expect <<-EOF &&
198 # branch.head initial-branch
203 git status --porcelain=v2 --branch --untracked-files=all >actual &&
204 test_cmp expect actual
207 test_expect_success
'confirm ignored files are not printed' '
208 test_when_finished "rm -f x.ign .gitignore" &&
209 echo x.ign >.gitignore &&
210 echo "ignore me" >x.ign &&
212 cat >expect <<-EOF &&
218 git status --porcelain=v2 --untracked-files=all >actual &&
219 test_cmp expect actual
222 test_expect_success
'ignored files are printed with --ignored' '
223 test_when_finished "rm -f x.ign .gitignore" &&
224 echo x.ign >.gitignore &&
225 echo "ignore me" >x.ign &&
227 cat >expect <<-EOF &&
234 git status --porcelain=v2 --ignored --untracked-files=all >actual &&
235 test_cmp expect actual
238 test_expect_success
'create and commit permanent ignore file' '
239 cat >.gitignore <<-EOF &&
244 git add .gitignore &&
245 git commit -m ignore_trash &&
246 H1=$(git rev-parse HEAD) &&
248 cat >expect <<-EOF &&
250 # branch.head initial-branch
253 git status --porcelain=v2 --branch >actual &&
254 test_cmp expect actual
257 test_expect_success
'verify --intent-to-add output' '
258 test_when_finished "git rm -f intent1.add intent2.add" &&
260 echo test >intent2.add &&
262 git add --intent-to-add intent1.add intent2.add &&
264 cat >expect <<-EOF &&
265 1 .A N... 000000 000000 100644 $ZERO_OID $ZERO_OID intent1.add
266 1 .A N... 000000 000000 100644 $ZERO_OID $ZERO_OID intent2.add
269 git status --porcelain=v2 >actual &&
270 test_cmp expect actual
273 test_expect_success
'verify AA (add-add) conflict' '
274 test_when_finished "git reset --hard" &&
276 git branch AA_A initial-branch &&
278 echo "Branch AA_A" >conflict.txt &&
279 OID_AA_A=$(git hash-object -t blob -- conflict.txt) &&
280 git add conflict.txt &&
281 git commit -m "branch aa_a" &&
283 git branch AA_B initial-branch &&
285 echo "Branch AA_B" >conflict.txt &&
286 OID_AA_B=$(git hash-object -t blob -- conflict.txt) &&
287 git add conflict.txt &&
288 git commit -m "branch aa_b" &&
290 git branch AA_M AA_B &&
292 test_must_fail git merge AA_A &&
294 HM=$(git rev-parse HEAD) &&
296 cat >expect <<-EOF &&
299 u AA N... 000000 100644 100644 100644 $ZERO_OID $OID_AA_B $OID_AA_A conflict.txt
302 git status --porcelain=v2 --branch --untracked-files=all >actual &&
303 test_cmp expect actual
306 test_expect_success
'verify UU (edit-edit) conflict' '
307 test_when_finished "git reset --hard" &&
309 git branch UU_ANC initial-branch &&
310 git checkout UU_ANC &&
311 echo "Ancestor" >conflict.txt &&
312 OID_UU_ANC=$(git hash-object -t blob -- conflict.txt) &&
313 git add conflict.txt &&
314 git commit -m "UU_ANC" &&
316 git branch UU_A UU_ANC &&
318 echo "Branch UU_A" >conflict.txt &&
319 OID_UU_A=$(git hash-object -t blob -- conflict.txt) &&
320 git add conflict.txt &&
321 git commit -m "branch uu_a" &&
323 git branch UU_B UU_ANC &&
325 echo "Branch UU_B" >conflict.txt &&
326 OID_UU_B=$(git hash-object -t blob -- conflict.txt) &&
327 git add conflict.txt &&
328 git commit -m "branch uu_b" &&
330 git branch UU_M UU_B &&
332 test_must_fail git merge UU_A &&
334 HM=$(git rev-parse HEAD) &&
336 cat >expect <<-EOF &&
339 u UU N... 100644 100644 100644 100644 $OID_UU_ANC $OID_UU_B $OID_UU_A conflict.txt
342 git status --porcelain=v2 --branch --untracked-files=all >actual &&
343 test_cmp expect actual
346 test_expect_success
'verify upstream fields in branch header' '
347 git checkout initial-branch &&
348 test_when_finished "rm -rf sub_repo" &&
349 git clone . sub_repo &&
351 ## Confirm local initial-branch tracks remote initial-branch.
353 HUF=$(git rev-parse HEAD) &&
355 cat >expect <<-EOF &&
357 # branch.head initial-branch
358 # branch.upstream origin/initial-branch
362 git status --porcelain=v2 --branch --untracked-files=all >actual &&
363 test_cmp expect actual &&
365 ## Test ahead/behind.
366 echo xyz >file_xyz &&
370 HUF=$(git rev-parse HEAD) &&
372 cat >expect <<-EOF &&
374 # branch.head initial-branch
375 # branch.upstream origin/initial-branch
379 git status --porcelain=v2 --branch --untracked-files=all >actual &&
380 test_cmp expect actual &&
382 ## Repeat the above but without --branch.
383 git status --porcelain=v2 --untracked-files=all >actual &&
384 test_must_be_empty actual &&
386 ## Test upstream-gone case. Fake this by pointing
387 ## origin/initial-branch at a non-existing commit.
388 git update-ref -d refs/remotes/origin/initial-branch &&
390 HUF=$(git rev-parse HEAD) &&
392 cat >expect <<-EOF &&
394 # branch.head initial-branch
395 # branch.upstream origin/initial-branch
398 git status --porcelain=v2 --branch --untracked-files=all >actual &&
399 test_cmp expect actual
403 test_expect_success
'verify --[no-]ahead-behind with V2 format' '
404 git checkout initial-branch &&
405 test_when_finished "rm -rf sub_repo" &&
406 git clone . sub_repo &&
408 ## Confirm local initial-branch tracks remote initial-branch.
410 HUF=$(git rev-parse HEAD) &&
412 # Confirm --no-ahead-behind reports traditional branch.ab with 0/0 for equal branches.
413 cat >expect <<-EOF &&
415 # branch.head initial-branch
416 # branch.upstream origin/initial-branch
420 git status --no-ahead-behind --porcelain=v2 --branch --untracked-files=all >actual &&
421 test_cmp expect actual &&
423 # Confirm --ahead-behind reports traditional branch.ab with 0/0.
424 cat >expect <<-EOF &&
426 # branch.head initial-branch
427 # branch.upstream origin/initial-branch
431 git status --ahead-behind --porcelain=v2 --branch --untracked-files=all >actual &&
432 test_cmp expect actual &&
434 ## Test non-equal ahead/behind.
435 echo xyz >file_xyz &&
439 HUF=$(git rev-parse HEAD) &&
441 # Confirm --no-ahead-behind reports branch.ab with ?/? for non-equal branches.
442 cat >expect <<-EOF &&
444 # branch.head initial-branch
445 # branch.upstream origin/initial-branch
449 git status --no-ahead-behind --porcelain=v2 --branch --untracked-files=all >actual &&
450 test_cmp expect actual &&
452 # Confirm --ahead-behind reports traditional branch.ab with 1/0.
453 cat >expect <<-EOF &&
455 # branch.head initial-branch
456 # branch.upstream origin/initial-branch
460 git status --ahead-behind --porcelain=v2 --branch --untracked-files=all >actual &&
461 test_cmp expect actual &&
463 # Confirm that "status.aheadbehind" DOES NOT work on V2 format.
464 git -c status.aheadbehind=false status --porcelain=v2 --branch --untracked-files=all >actual &&
465 test_cmp expect actual &&
467 # Confirm that "status.aheadbehind" DOES NOT work on V2 format.
468 git -c status.aheadbehind=true status --porcelain=v2 --branch --untracked-files=all >actual &&
469 test_cmp expect actual
473 test_expect_success
'create and add submodule, submodule appears clean (A. S...)' '
474 git checkout initial-branch &&
475 git clone . sub_repo &&
476 git clone . super_repo &&
477 test_config_global protocol.file.allow always &&
479 git submodule add ../sub_repo sub1 &&
481 ## Confirm stage/add of clean submodule.
482 HMOD=$(git hash-object -t blob -- .gitmodules) &&
483 HSUP=$(git rev-parse HEAD) &&
486 cat >expect <<-EOF &&
488 # branch.head initial-branch
489 # branch.upstream origin/initial-branch
491 1 A. N... 000000 100644 100644 $ZERO_OID $HMOD .gitmodules
492 1 A. S... 000000 160000 160000 $ZERO_OID $HSUB sub1
495 git status --porcelain=v2 --branch --untracked-files=all >actual &&
496 test_cmp expect actual
500 test_expect_success
'untracked changes in added submodule (AM S..U)' '
502 ## create untracked file in the submodule.
504 echo "xxxx" >file_in_sub
507 HMOD=$(git hash-object -t blob -- .gitmodules) &&
508 HSUP=$(git rev-parse HEAD) &&
511 cat >expect <<-EOF &&
513 # branch.head initial-branch
514 # branch.upstream origin/initial-branch
516 1 A. N... 000000 100644 100644 $ZERO_OID $HMOD .gitmodules
517 1 AM S..U 000000 160000 160000 $ZERO_OID $HSUB sub1
520 git status --porcelain=v2 --branch --untracked-files=all >actual &&
521 test_cmp expect actual
525 test_expect_success
'staged changes in added submodule (AM S.M.)' '
527 ## stage the changes in the submodule.
532 HMOD=$(git hash-object -t blob -- .gitmodules) &&
533 HSUP=$(git rev-parse HEAD) &&
536 cat >expect <<-EOF &&
538 # branch.head initial-branch
539 # branch.upstream origin/initial-branch
541 1 A. N... 000000 100644 100644 $ZERO_OID $HMOD .gitmodules
542 1 AM S.M. 000000 160000 160000 $ZERO_OID $HSUB sub1
545 git status --porcelain=v2 --branch --untracked-files=all >actual &&
546 test_cmp expect actual
550 test_expect_success
'staged and unstaged changes in added (AM S.M.)' '
553 ## make additional unstaged changes (on the same file) in the submodule.
554 ## This does not cause us to get S.MU (because the submodule does not report
555 ## a "?" line for the unstaged changes).
556 echo "more changes" >>file_in_sub
559 HMOD=$(git hash-object -t blob -- .gitmodules) &&
560 HSUP=$(git rev-parse HEAD) &&
563 cat >expect <<-EOF &&
565 # branch.head initial-branch
566 # branch.upstream origin/initial-branch
568 1 A. N... 000000 100644 100644 $ZERO_OID $HMOD .gitmodules
569 1 AM S.M. 000000 160000 160000 $ZERO_OID $HSUB sub1
572 git status --porcelain=v2 --branch --untracked-files=all >actual &&
573 test_cmp expect actual
577 test_expect_success
'staged and untracked changes in added submodule (AM S.MU)' '
580 ## stage new changes in tracked file.
581 git add file_in_sub &&
582 ## create new untracked file.
583 echo "yyyy" >>another_file_in_sub
586 HMOD=$(git hash-object -t blob -- .gitmodules) &&
587 HSUP=$(git rev-parse HEAD) &&
590 cat >expect <<-EOF &&
592 # branch.head initial-branch
593 # branch.upstream origin/initial-branch
595 1 A. N... 000000 100644 100644 $ZERO_OID $HMOD .gitmodules
596 1 AM S.MU 000000 160000 160000 $ZERO_OID $HSUB sub1
599 git status --porcelain=v2 --branch --untracked-files=all >actual &&
600 test_cmp expect actual
604 test_expect_success
'commit within the submodule appears as new commit in super (AM SC..)' '
607 ## Make a new commit in the submodule.
608 git add file_in_sub &&
609 rm -f another_file_in_sub &&
610 git commit -m "new commit"
613 HMOD=$(git hash-object -t blob -- .gitmodules) &&
614 HSUP=$(git rev-parse HEAD) &&
617 cat >expect <<-EOF &&
619 # branch.head initial-branch
620 # branch.upstream origin/initial-branch
622 1 A. N... 000000 100644 100644 $ZERO_OID $HMOD .gitmodules
623 1 AM SC.. 000000 160000 160000 $ZERO_OID $HSUB sub1
626 git status --porcelain=v2 --branch --untracked-files=all >actual &&
627 test_cmp expect actual
631 test_expect_success
'stage submodule in super and commit' '
633 ## Stage the new submodule commit in the super.
635 ## Commit the super so that the sub no longer appears as added.
636 git commit -m "super commit" &&
638 HSUP=$(git rev-parse HEAD) &&
640 cat >expect <<-EOF &&
642 # branch.head initial-branch
643 # branch.upstream origin/initial-branch
647 git status --porcelain=v2 --branch --untracked-files=all >actual &&
648 test_cmp expect actual
652 test_expect_success
'make unstaged changes in existing submodule (.M S.M.)' '
655 echo "zzzz" >>file_in_sub
658 HSUP=$(git rev-parse HEAD) &&
659 HSUB=$(cd sub1 && git rev-parse HEAD) &&
661 cat >expect <<-EOF &&
663 # branch.head initial-branch
664 # branch.upstream origin/initial-branch
666 1 .M S.M. 160000 160000 160000 $HSUB $HSUB sub1
669 git status --porcelain=v2 --branch --untracked-files=all >actual &&
670 test_cmp expect actual