3 test_description='git status --porcelain=v2
5 This test exercises porcelain V2 output for git status.'
8 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=master
9 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
14 test_expect_success setup '
16 git config core.autocrlf false &&
21 echo a >dir1/file_a &&
25 test_expect_success 'before initial commit, nothing added, only untracked' '
27 # branch.oid (initial)
37 git status --porcelain=v2 --branch --untracked-files=normal >actual &&
38 test_cmp expect actual
41 test_expect_success 'before initial commit, things added' '
42 git add file_x file_y file_z dir1 &&
43 OID_A=$(git hash-object -t blob -- dir1/file_a) &&
44 OID_B=$(git hash-object -t blob -- dir1/file_b) &&
45 OID_X=$(git hash-object -t blob -- file_x) &&
46 OID_Y=$(git hash-object -t blob -- file_y) &&
47 OID_Z=$(git hash-object -t blob -- file_z) &&
50 # branch.oid (initial)
52 1 A. N... 000000 100644 100644 $ZERO_OID $OID_A dir1/file_a
53 1 A. N... 000000 100644 100644 $ZERO_OID $OID_B dir1/file_b
54 1 A. N... 000000 100644 100644 $ZERO_OID $OID_X file_x
55 1 A. N... 000000 100644 100644 $ZERO_OID $OID_Y file_y
56 1 A. N... 000000 100644 100644 $ZERO_OID $OID_Z file_z
61 git status --porcelain=v2 --branch --untracked-files=all >actual &&
62 test_cmp expect actual
65 test_expect_success 'before initial commit, things added (-z)' '
66 lf_to_nul >expect <<-EOF &&
67 # branch.oid (initial)
69 1 A. N... 000000 100644 100644 $ZERO_OID $OID_A dir1/file_a
70 1 A. N... 000000 100644 100644 $ZERO_OID $OID_B dir1/file_b
71 1 A. N... 000000 100644 100644 $ZERO_OID $OID_X file_x
72 1 A. N... 000000 100644 100644 $ZERO_OID $OID_Y file_y
73 1 A. N... 000000 100644 100644 $ZERO_OID $OID_Z file_z
78 git status -z --porcelain=v2 --branch --untracked-files=all >actual &&
79 test_cmp expect actual
82 test_expect_success 'make first commit, comfirm HEAD oid and branch' '
83 git commit -m initial &&
84 H0=$(git rev-parse HEAD) &&
92 git status --porcelain=v2 --branch --untracked-files=all >actual &&
93 test_cmp expect actual
96 test_expect_success 'after first commit, create unstaged changes' '
98 OID_X1=$(git hash-object -t blob -- file_x) &&
100 H0=$(git rev-parse HEAD) &&
102 cat >expect <<-EOF &&
105 1 .M N... 100644 100644 100644 $OID_X $OID_X file_x
106 1 .D N... 100644 100644 000000 $OID_Z $OID_Z file_z
111 git status --porcelain=v2 --branch --untracked-files=all >actual &&
112 test_cmp expect actual
115 test_expect_success 'after first commit but omit untracked files and branch' '
116 cat >expect <<-EOF &&
117 1 .M N... 100644 100644 100644 $OID_X $OID_X file_x
118 1 .D N... 100644 100644 000000 $OID_Z $OID_Z file_z
121 git status --porcelain=v2 --untracked-files=no >actual &&
122 test_cmp expect actual
125 test_expect_success 'after first commit, stage existing changes' '
128 H0=$(git rev-parse HEAD) &&
130 cat >expect <<-EOF &&
133 1 M. N... 100644 100644 100644 $OID_X $OID_X1 file_x
134 1 D. N... 100644 000000 000000 $OID_Z $ZERO_OID file_z
139 git status --porcelain=v2 --branch --untracked-files=all >actual &&
140 test_cmp expect actual
143 test_expect_success 'rename causes 2 path lines' '
144 git mv file_y renamed_y &&
145 H0=$(git rev-parse HEAD) &&
147 q_to_tab >expect <<-EOF &&
150 1 M. N... 100644 100644 100644 $OID_X $OID_X1 file_x
151 1 D. N... 100644 000000 000000 $OID_Z $ZERO_OID file_z
152 2 R. N... 100644 100644 100644 $OID_Y $OID_Y R100 renamed_yQfile_y
157 git status --porcelain=v2 --branch --untracked-files=all >actual &&
158 test_cmp expect actual
161 test_expect_success 'rename causes 2 path lines (-z)' '
162 H0=$(git rev-parse HEAD) &&
164 ## Lines use NUL path separator and line terminator, so double transform here.
165 q_to_nul <<-EOF | lf_to_nul >expect &&
168 1 M. N... 100644 100644 100644 $OID_X $OID_X1 file_x
169 1 D. N... 100644 000000 000000 $OID_Z $ZERO_OID file_z
170 2 R. N... 100644 100644 100644 $OID_Y $OID_Y R100 renamed_yQfile_y
175 git status --porcelain=v2 --branch --untracked-files=all -z >actual &&
176 test_cmp expect actual
179 test_expect_success 'make second commit, confirm clean and new HEAD oid' '
180 git commit -m second &&
181 H1=$(git rev-parse HEAD) &&
183 cat >expect <<-EOF &&
190 git status --porcelain=v2 --branch --untracked-files=all >actual &&
191 test_cmp expect actual
194 test_expect_success 'confirm ignored files are not printed' '
195 test_when_finished "rm -f x.ign .gitignore" &&
196 echo x.ign >.gitignore &&
197 echo "ignore me" >x.ign &&
199 cat >expect <<-EOF &&
205 git status --porcelain=v2 --untracked-files=all >actual &&
206 test_cmp expect actual
209 test_expect_success 'ignored files are printed with --ignored' '
210 test_when_finished "rm -f x.ign .gitignore" &&
211 echo x.ign >.gitignore &&
212 echo "ignore me" >x.ign &&
214 cat >expect <<-EOF &&
221 git status --porcelain=v2 --ignored --untracked-files=all >actual &&
222 test_cmp expect actual
225 test_expect_success 'create and commit permanent ignore file' '
226 cat >.gitignore <<-EOF &&
231 git add .gitignore &&
232 git commit -m ignore_trash &&
233 H1=$(git rev-parse HEAD) &&
235 cat >expect <<-EOF &&
240 git status --porcelain=v2 --branch >actual &&
241 test_cmp expect actual
244 test_expect_success 'verify --intent-to-add output' '
245 test_when_finished "git rm -f intent1.add intent2.add" &&
247 echo test >intent2.add &&
249 git add --intent-to-add intent1.add intent2.add &&
251 cat >expect <<-EOF &&
252 1 .A N... 000000 000000 100644 $ZERO_OID $ZERO_OID intent1.add
253 1 .A N... 000000 000000 100644 $ZERO_OID $ZERO_OID intent2.add
256 git status --porcelain=v2 >actual &&
257 test_cmp expect actual
260 test_expect_success 'verify AA (add-add) conflict' '
261 test_when_finished "git reset --hard" &&
263 git branch AA_A master &&
265 echo "Branch AA_A" >conflict.txt &&
266 OID_AA_A=$(git hash-object -t blob -- conflict.txt) &&
267 git add conflict.txt &&
268 git commit -m "branch aa_a" &&
270 git branch AA_B master &&
272 echo "Branch AA_B" >conflict.txt &&
273 OID_AA_B=$(git hash-object -t blob -- conflict.txt) &&
274 git add conflict.txt &&
275 git commit -m "branch aa_b" &&
277 git branch AA_M AA_B &&
279 test_must_fail git merge AA_A &&
281 HM=$(git rev-parse HEAD) &&
283 cat >expect <<-EOF &&
286 u AA N... 000000 100644 100644 100644 $ZERO_OID $OID_AA_B $OID_AA_A conflict.txt
289 git status --porcelain=v2 --branch --untracked-files=all >actual &&
290 test_cmp expect actual
293 test_expect_success 'verify UU (edit-edit) conflict' '
294 test_when_finished "git reset --hard" &&
296 git branch UU_ANC master &&
297 git checkout UU_ANC &&
298 echo "Ancestor" >conflict.txt &&
299 OID_UU_ANC=$(git hash-object -t blob -- conflict.txt) &&
300 git add conflict.txt &&
301 git commit -m "UU_ANC" &&
303 git branch UU_A UU_ANC &&
305 echo "Branch UU_A" >conflict.txt &&
306 OID_UU_A=$(git hash-object -t blob -- conflict.txt) &&
307 git add conflict.txt &&
308 git commit -m "branch uu_a" &&
310 git branch UU_B UU_ANC &&
312 echo "Branch UU_B" >conflict.txt &&
313 OID_UU_B=$(git hash-object -t blob -- conflict.txt) &&
314 git add conflict.txt &&
315 git commit -m "branch uu_b" &&
317 git branch UU_M UU_B &&
319 test_must_fail git merge UU_A &&
321 HM=$(git rev-parse HEAD) &&
323 cat >expect <<-EOF &&
326 u UU N... 100644 100644 100644 100644 $OID_UU_ANC $OID_UU_B $OID_UU_A conflict.txt
329 git status --porcelain=v2 --branch --untracked-files=all >actual &&
330 test_cmp expect actual
333 test_expect_success 'verify upstream fields in branch header' '
334 git checkout master &&
335 test_when_finished "rm -rf sub_repo" &&
336 git clone . sub_repo &&
338 ## Confirm local master tracks remote master.
340 HUF=$(git rev-parse HEAD) &&
342 cat >expect <<-EOF &&
345 # branch.upstream origin/master
349 git status --porcelain=v2 --branch --untracked-files=all >actual &&
350 test_cmp expect actual &&
352 ## Test ahead/behind.
353 echo xyz >file_xyz &&
357 HUF=$(git rev-parse HEAD) &&
359 cat >expect <<-EOF &&
362 # branch.upstream origin/master
366 git status --porcelain=v2 --branch --untracked-files=all >actual &&
367 test_cmp expect actual &&
369 ## Repeat the above but without --branch.
370 git status --porcelain=v2 --untracked-files=all >actual &&
371 test_must_be_empty 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 'verify --[no-]ahead-behind with V2 format' '
394 git checkout master &&
395 test_when_finished "rm -rf sub_repo" &&
396 git clone . sub_repo &&
398 ## Confirm local master tracks remote master.
400 HUF=$(git rev-parse HEAD) &&
402 # Confirm --no-ahead-behind reports traditional branch.ab with 0/0 for equal branches.
403 cat >expect <<-EOF &&
406 # branch.upstream origin/master
410 git status --no-ahead-behind --porcelain=v2 --branch --untracked-files=all >actual &&
411 test_cmp expect actual &&
413 # Confirm --ahead-behind reports traditional branch.ab with 0/0.
414 cat >expect <<-EOF &&
417 # branch.upstream origin/master
421 git status --ahead-behind --porcelain=v2 --branch --untracked-files=all >actual &&
422 test_cmp expect actual &&
424 ## Test non-equal ahead/behind.
425 echo xyz >file_xyz &&
429 HUF=$(git rev-parse HEAD) &&
431 # Confirm --no-ahead-behind reports branch.ab with ?/? for non-equal branches.
432 cat >expect <<-EOF &&
435 # branch.upstream origin/master
439 git status --no-ahead-behind --porcelain=v2 --branch --untracked-files=all >actual &&
440 test_cmp expect actual &&
442 # Confirm --ahead-behind reports traditional branch.ab with 1/0.
443 cat >expect <<-EOF &&
446 # branch.upstream origin/master
450 git status --ahead-behind --porcelain=v2 --branch --untracked-files=all >actual &&
451 test_cmp expect actual &&
453 # Confirm that "status.aheadbehind" DOES NOT work on V2 format.
454 git -c status.aheadbehind=false status --porcelain=v2 --branch --untracked-files=all >actual &&
455 test_cmp expect actual &&
457 # Confirm that "status.aheadbehind" DOES NOT work on V2 format.
458 git -c status.aheadbehind=true status --porcelain=v2 --branch --untracked-files=all >actual &&
459 test_cmp expect actual
463 test_expect_success 'create and add submodule, submodule appears clean (A. S...)' '
464 git checkout master &&
465 git clone . sub_repo &&
466 git clone . super_repo &&
468 git submodule add ../sub_repo sub1 &&
470 ## Confirm stage/add of clean submodule.
471 HMOD=$(git hash-object -t blob -- .gitmodules) &&
472 HSUP=$(git rev-parse HEAD) &&
475 cat >expect <<-EOF &&
478 # branch.upstream origin/master
480 1 A. N... 000000 100644 100644 $ZERO_OID $HMOD .gitmodules
481 1 A. S... 000000 160000 160000 $ZERO_OID $HSUB sub1
484 git status --porcelain=v2 --branch --untracked-files=all >actual &&
485 test_cmp expect actual
489 test_expect_success 'untracked changes in added submodule (AM S..U)' '
491 ## create untracked file in the submodule.
493 echo "xxxx" >file_in_sub
496 HMOD=$(git hash-object -t blob -- .gitmodules) &&
497 HSUP=$(git rev-parse HEAD) &&
500 cat >expect <<-EOF &&
503 # branch.upstream origin/master
505 1 A. N... 000000 100644 100644 $ZERO_OID $HMOD .gitmodules
506 1 AM S..U 000000 160000 160000 $ZERO_OID $HSUB sub1
509 git status --porcelain=v2 --branch --untracked-files=all >actual &&
510 test_cmp expect actual
514 test_expect_success 'staged changes in added submodule (AM S.M.)' '
516 ## stage the changes in the submodule.
521 HMOD=$(git hash-object -t blob -- .gitmodules) &&
522 HSUP=$(git rev-parse HEAD) &&
525 cat >expect <<-EOF &&
528 # branch.upstream origin/master
530 1 A. N... 000000 100644 100644 $ZERO_OID $HMOD .gitmodules
531 1 AM S.M. 000000 160000 160000 $ZERO_OID $HSUB sub1
534 git status --porcelain=v2 --branch --untracked-files=all >actual &&
535 test_cmp expect actual
539 test_expect_success 'staged and unstaged changes in added (AM S.M.)' '
542 ## make additional unstaged changes (on the same file) in the submodule.
543 ## This does not cause us to get S.MU (because the submodule does not report
544 ## a "?" line for the unstaged changes).
545 echo "more changes" >>file_in_sub
548 HMOD=$(git hash-object -t blob -- .gitmodules) &&
549 HSUP=$(git rev-parse HEAD) &&
552 cat >expect <<-EOF &&
555 # branch.upstream origin/master
557 1 A. N... 000000 100644 100644 $ZERO_OID $HMOD .gitmodules
558 1 AM S.M. 000000 160000 160000 $ZERO_OID $HSUB sub1
561 git status --porcelain=v2 --branch --untracked-files=all >actual &&
562 test_cmp expect actual
566 test_expect_success 'staged and untracked changes in added submodule (AM S.MU)' '
569 ## stage new changes in tracked file.
570 git add file_in_sub &&
571 ## create new untracked file.
572 echo "yyyy" >>another_file_in_sub
575 HMOD=$(git hash-object -t blob -- .gitmodules) &&
576 HSUP=$(git rev-parse HEAD) &&
579 cat >expect <<-EOF &&
582 # branch.upstream origin/master
584 1 A. N... 000000 100644 100644 $ZERO_OID $HMOD .gitmodules
585 1 AM S.MU 000000 160000 160000 $ZERO_OID $HSUB sub1
588 git status --porcelain=v2 --branch --untracked-files=all >actual &&
589 test_cmp expect actual
593 test_expect_success 'commit within the submodule appears as new commit in super (AM SC..)' '
596 ## Make a new commit in the submodule.
597 git add file_in_sub &&
598 rm -f another_file_in_sub &&
599 git commit -m "new commit"
602 HMOD=$(git hash-object -t blob -- .gitmodules) &&
603 HSUP=$(git rev-parse HEAD) &&
606 cat >expect <<-EOF &&
609 # branch.upstream origin/master
611 1 A. N... 000000 100644 100644 $ZERO_OID $HMOD .gitmodules
612 1 AM SC.. 000000 160000 160000 $ZERO_OID $HSUB sub1
615 git status --porcelain=v2 --branch --untracked-files=all >actual &&
616 test_cmp expect actual
620 test_expect_success 'stage submodule in super and commit' '
622 ## Stage the new submodule commit in the super.
624 ## Commit the super so that the sub no longer appears as added.
625 git commit -m "super commit" &&
627 HSUP=$(git rev-parse HEAD) &&
629 cat >expect <<-EOF &&
632 # branch.upstream origin/master
636 git status --porcelain=v2 --branch --untracked-files=all >actual &&
637 test_cmp expect actual
641 test_expect_success 'make unstaged changes in existing submodule (.M S.M.)' '
644 echo "zzzz" >>file_in_sub
647 HSUP=$(git rev-parse HEAD) &&
648 HSUB=$(cd sub1 && git rev-parse HEAD) &&
650 cat >expect <<-EOF &&
653 # branch.upstream origin/master
655 1 .M S.M. 160000 160000 160000 $HSUB $HSUB sub1
658 git status --porcelain=v2 --branch --untracked-files=all >actual &&
659 test_cmp expect actual