3 test_description
='git status --porcelain=v2
5 This test exercises porcelain V2 output for git status.'
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 but omit untracked files and branch' '
114 cat >expect <<-EOF &&
115 1 .M N... 100644 100644 100644 $OID_X $OID_X file_x
116 1 .D N... 100644 100644 000000 $OID_Z $OID_Z file_z
119 git status --porcelain=v2 --untracked-files=no >actual &&
120 test_cmp expect actual
123 test_expect_success
'after first commit, stage existing changes' '
126 H0=$(git rev-parse HEAD) &&
128 cat >expect <<-EOF &&
130 # branch.head initial-branch
131 1 M. N... 100644 100644 100644 $OID_X $OID_X1 file_x
132 1 D. N... 100644 000000 000000 $OID_Z $ZERO_OID file_z
137 git status --porcelain=v2 --branch --untracked-files=all >actual &&
138 test_cmp expect actual
141 test_expect_success
'rename causes 2 path lines' '
142 git mv file_y renamed_y &&
143 H0=$(git rev-parse HEAD) &&
145 q_to_tab >expect <<-EOF &&
147 # branch.head initial-branch
148 1 M. N... 100644 100644 100644 $OID_X $OID_X1 file_x
149 1 D. N... 100644 000000 000000 $OID_Z $ZERO_OID file_z
150 2 R. N... 100644 100644 100644 $OID_Y $OID_Y R100 renamed_yQfile_y
155 git status --porcelain=v2 --branch --untracked-files=all >actual &&
156 test_cmp expect actual
159 test_expect_success
'rename causes 2 path lines (-z)' '
160 H0=$(git rev-parse HEAD) &&
162 ## Lines use NUL path separator and line terminator, so double transform here.
163 q_to_nul <<-EOF | lf_to_nul >expect &&
165 # branch.head initial-branch
166 1 M. N... 100644 100644 100644 $OID_X $OID_X1 file_x
167 1 D. N... 100644 000000 000000 $OID_Z $ZERO_OID file_z
168 2 R. N... 100644 100644 100644 $OID_Y $OID_Y R100 renamed_yQfile_y
173 git status --porcelain=v2 --branch --untracked-files=all -z >actual &&
174 test_cmp expect actual
177 test_expect_success
'make second commit, confirm clean and new HEAD oid' '
178 git commit -m second &&
179 H1=$(git rev-parse HEAD) &&
181 cat >expect <<-EOF &&
183 # branch.head initial-branch
188 git status --porcelain=v2 --branch --untracked-files=all >actual &&
189 test_cmp expect actual
192 test_expect_success
'confirm ignored files are not printed' '
193 test_when_finished "rm -f x.ign .gitignore" &&
194 echo x.ign >.gitignore &&
195 echo "ignore me" >x.ign &&
197 cat >expect <<-EOF &&
203 git status --porcelain=v2 --untracked-files=all >actual &&
204 test_cmp expect actual
207 test_expect_success
'ignored files are printed with --ignored' '
208 test_when_finished "rm -f x.ign .gitignore" &&
209 echo x.ign >.gitignore &&
210 echo "ignore me" >x.ign &&
212 cat >expect <<-EOF &&
219 git status --porcelain=v2 --ignored --untracked-files=all >actual &&
220 test_cmp expect actual
223 test_expect_success
'create and commit permanent ignore file' '
224 cat >.gitignore <<-EOF &&
229 git add .gitignore &&
230 git commit -m ignore_trash &&
231 H1=$(git rev-parse HEAD) &&
233 cat >expect <<-EOF &&
235 # branch.head initial-branch
238 git status --porcelain=v2 --branch >actual &&
239 test_cmp expect actual
242 test_expect_success
'verify --intent-to-add output' '
243 test_when_finished "git rm -f intent1.add intent2.add" &&
245 echo test >intent2.add &&
247 git add --intent-to-add intent1.add intent2.add &&
249 cat >expect <<-EOF &&
250 1 .A N... 000000 000000 100644 $ZERO_OID $ZERO_OID intent1.add
251 1 .A N... 000000 000000 100644 $ZERO_OID $ZERO_OID intent2.add
254 git status --porcelain=v2 >actual &&
255 test_cmp expect actual
258 test_expect_success
'verify AA (add-add) conflict' '
259 test_when_finished "git reset --hard" &&
261 git branch AA_A initial-branch &&
263 echo "Branch AA_A" >conflict.txt &&
264 OID_AA_A=$(git hash-object -t blob -- conflict.txt) &&
265 git add conflict.txt &&
266 git commit -m "branch aa_a" &&
268 git branch AA_B initial-branch &&
270 echo "Branch AA_B" >conflict.txt &&
271 OID_AA_B=$(git hash-object -t blob -- conflict.txt) &&
272 git add conflict.txt &&
273 git commit -m "branch aa_b" &&
275 git branch AA_M AA_B &&
277 test_must_fail git merge AA_A &&
279 HM=$(git rev-parse HEAD) &&
281 cat >expect <<-EOF &&
284 u AA N... 000000 100644 100644 100644 $ZERO_OID $OID_AA_B $OID_AA_A conflict.txt
287 git status --porcelain=v2 --branch --untracked-files=all >actual &&
288 test_cmp expect actual
291 test_expect_success
'verify UU (edit-edit) conflict' '
292 test_when_finished "git reset --hard" &&
294 git branch UU_ANC initial-branch &&
295 git checkout UU_ANC &&
296 echo "Ancestor" >conflict.txt &&
297 OID_UU_ANC=$(git hash-object -t blob -- conflict.txt) &&
298 git add conflict.txt &&
299 git commit -m "UU_ANC" &&
301 git branch UU_A UU_ANC &&
303 echo "Branch UU_A" >conflict.txt &&
304 OID_UU_A=$(git hash-object -t blob -- conflict.txt) &&
305 git add conflict.txt &&
306 git commit -m "branch uu_a" &&
308 git branch UU_B UU_ANC &&
310 echo "Branch UU_B" >conflict.txt &&
311 OID_UU_B=$(git hash-object -t blob -- conflict.txt) &&
312 git add conflict.txt &&
313 git commit -m "branch uu_b" &&
315 git branch UU_M UU_B &&
317 test_must_fail git merge UU_A &&
319 HM=$(git rev-parse HEAD) &&
321 cat >expect <<-EOF &&
324 u UU N... 100644 100644 100644 100644 $OID_UU_ANC $OID_UU_B $OID_UU_A conflict.txt
327 git status --porcelain=v2 --branch --untracked-files=all >actual &&
328 test_cmp expect actual
331 test_expect_success
'verify upstream fields in branch header' '
332 git checkout initial-branch &&
333 test_when_finished "rm -rf sub_repo" &&
334 git clone . sub_repo &&
336 ## Confirm local initial-branch tracks remote initial-branch.
338 HUF=$(git rev-parse HEAD) &&
340 cat >expect <<-EOF &&
342 # branch.head initial-branch
343 # branch.upstream origin/initial-branch
347 git status --porcelain=v2 --branch --untracked-files=all >actual &&
348 test_cmp expect actual &&
350 ## Test ahead/behind.
351 echo xyz >file_xyz &&
355 HUF=$(git rev-parse HEAD) &&
357 cat >expect <<-EOF &&
359 # branch.head initial-branch
360 # branch.upstream origin/initial-branch
364 git status --porcelain=v2 --branch --untracked-files=all >actual &&
365 test_cmp expect actual &&
367 ## Repeat the above but without --branch.
368 git status --porcelain=v2 --untracked-files=all >actual &&
369 test_must_be_empty actual &&
371 ## Test upstream-gone case. Fake this by pointing
372 ## origin/initial-branch at a non-existing commit.
373 OLD=$(git rev-parse origin/initial-branch) &&
375 mv .git/packed-refs .git/old-packed-refs &&
376 sed "s/$OLD/$NEW/g" <.git/old-packed-refs >.git/packed-refs &&
378 HUF=$(git rev-parse HEAD) &&
380 cat >expect <<-EOF &&
382 # branch.head initial-branch
383 # branch.upstream origin/initial-branch
386 git status --porcelain=v2 --branch --untracked-files=all >actual &&
387 test_cmp expect actual
391 test_expect_success
'verify --[no-]ahead-behind with V2 format' '
392 git checkout initial-branch &&
393 test_when_finished "rm -rf sub_repo" &&
394 git clone . sub_repo &&
396 ## Confirm local initial-branch tracks remote initial-branch.
398 HUF=$(git rev-parse HEAD) &&
400 # Confirm --no-ahead-behind reports traditional branch.ab with 0/0 for equal branches.
401 cat >expect <<-EOF &&
403 # branch.head initial-branch
404 # branch.upstream origin/initial-branch
408 git status --no-ahead-behind --porcelain=v2 --branch --untracked-files=all >actual &&
409 test_cmp expect actual &&
411 # Confirm --ahead-behind reports traditional branch.ab with 0/0.
412 cat >expect <<-EOF &&
414 # branch.head initial-branch
415 # branch.upstream origin/initial-branch
419 git status --ahead-behind --porcelain=v2 --branch --untracked-files=all >actual &&
420 test_cmp expect actual &&
422 ## Test non-equal ahead/behind.
423 echo xyz >file_xyz &&
427 HUF=$(git rev-parse HEAD) &&
429 # Confirm --no-ahead-behind reports branch.ab with ?/? for non-equal branches.
430 cat >expect <<-EOF &&
432 # branch.head initial-branch
433 # branch.upstream origin/initial-branch
437 git status --no-ahead-behind --porcelain=v2 --branch --untracked-files=all >actual &&
438 test_cmp expect actual &&
440 # Confirm --ahead-behind reports traditional branch.ab with 1/0.
441 cat >expect <<-EOF &&
443 # branch.head initial-branch
444 # branch.upstream origin/initial-branch
448 git status --ahead-behind --porcelain=v2 --branch --untracked-files=all >actual &&
449 test_cmp expect actual &&
451 # Confirm that "status.aheadbehind" DOES NOT work on V2 format.
452 git -c status.aheadbehind=false status --porcelain=v2 --branch --untracked-files=all >actual &&
453 test_cmp expect actual &&
455 # Confirm that "status.aheadbehind" DOES NOT work on V2 format.
456 git -c status.aheadbehind=true status --porcelain=v2 --branch --untracked-files=all >actual &&
457 test_cmp expect actual
461 test_expect_success
'create and add submodule, submodule appears clean (A. S...)' '
462 git checkout initial-branch &&
463 git clone . sub_repo &&
464 git clone . super_repo &&
465 test_config_global protocol.file.allow always &&
467 git submodule add ../sub_repo sub1 &&
469 ## Confirm stage/add of clean submodule.
470 HMOD=$(git hash-object -t blob -- .gitmodules) &&
471 HSUP=$(git rev-parse HEAD) &&
474 cat >expect <<-EOF &&
476 # branch.head initial-branch
477 # branch.upstream origin/initial-branch
479 1 A. N... 000000 100644 100644 $ZERO_OID $HMOD .gitmodules
480 1 A. S... 000000 160000 160000 $ZERO_OID $HSUB sub1
483 git status --porcelain=v2 --branch --untracked-files=all >actual &&
484 test_cmp expect actual
488 test_expect_success
'untracked changes in added submodule (AM S..U)' '
490 ## create untracked file in the submodule.
492 echo "xxxx" >file_in_sub
495 HMOD=$(git hash-object -t blob -- .gitmodules) &&
496 HSUP=$(git rev-parse HEAD) &&
499 cat >expect <<-EOF &&
501 # branch.head initial-branch
502 # branch.upstream origin/initial-branch
504 1 A. N... 000000 100644 100644 $ZERO_OID $HMOD .gitmodules
505 1 AM S..U 000000 160000 160000 $ZERO_OID $HSUB sub1
508 git status --porcelain=v2 --branch --untracked-files=all >actual &&
509 test_cmp expect actual
513 test_expect_success
'staged changes in added submodule (AM S.M.)' '
515 ## stage the changes in the submodule.
520 HMOD=$(git hash-object -t blob -- .gitmodules) &&
521 HSUP=$(git rev-parse HEAD) &&
524 cat >expect <<-EOF &&
526 # branch.head initial-branch
527 # branch.upstream origin/initial-branch
529 1 A. N... 000000 100644 100644 $ZERO_OID $HMOD .gitmodules
530 1 AM S.M. 000000 160000 160000 $ZERO_OID $HSUB sub1
533 git status --porcelain=v2 --branch --untracked-files=all >actual &&
534 test_cmp expect actual
538 test_expect_success
'staged and unstaged changes in added (AM S.M.)' '
541 ## make additional unstaged changes (on the same file) in the submodule.
542 ## This does not cause us to get S.MU (because the submodule does not report
543 ## a "?" line for the unstaged changes).
544 echo "more changes" >>file_in_sub
547 HMOD=$(git hash-object -t blob -- .gitmodules) &&
548 HSUP=$(git rev-parse HEAD) &&
551 cat >expect <<-EOF &&
553 # branch.head initial-branch
554 # branch.upstream origin/initial-branch
556 1 A. N... 000000 100644 100644 $ZERO_OID $HMOD .gitmodules
557 1 AM S.M. 000000 160000 160000 $ZERO_OID $HSUB sub1
560 git status --porcelain=v2 --branch --untracked-files=all >actual &&
561 test_cmp expect actual
565 test_expect_success
'staged and untracked changes in added submodule (AM S.MU)' '
568 ## stage new changes in tracked file.
569 git add file_in_sub &&
570 ## create new untracked file.
571 echo "yyyy" >>another_file_in_sub
574 HMOD=$(git hash-object -t blob -- .gitmodules) &&
575 HSUP=$(git rev-parse HEAD) &&
578 cat >expect <<-EOF &&
580 # branch.head initial-branch
581 # branch.upstream origin/initial-branch
583 1 A. N... 000000 100644 100644 $ZERO_OID $HMOD .gitmodules
584 1 AM S.MU 000000 160000 160000 $ZERO_OID $HSUB sub1
587 git status --porcelain=v2 --branch --untracked-files=all >actual &&
588 test_cmp expect actual
592 test_expect_success
'commit within the submodule appears as new commit in super (AM SC..)' '
595 ## Make a new commit in the submodule.
596 git add file_in_sub &&
597 rm -f another_file_in_sub &&
598 git commit -m "new commit"
601 HMOD=$(git hash-object -t blob -- .gitmodules) &&
602 HSUP=$(git rev-parse HEAD) &&
605 cat >expect <<-EOF &&
607 # branch.head initial-branch
608 # branch.upstream origin/initial-branch
610 1 A. N... 000000 100644 100644 $ZERO_OID $HMOD .gitmodules
611 1 AM SC.. 000000 160000 160000 $ZERO_OID $HSUB sub1
614 git status --porcelain=v2 --branch --untracked-files=all >actual &&
615 test_cmp expect actual
619 test_expect_success
'stage submodule in super and commit' '
621 ## Stage the new submodule commit in the super.
623 ## Commit the super so that the sub no longer appears as added.
624 git commit -m "super commit" &&
626 HSUP=$(git rev-parse HEAD) &&
628 cat >expect <<-EOF &&
630 # branch.head initial-branch
631 # branch.upstream origin/initial-branch
635 git status --porcelain=v2 --branch --untracked-files=all >actual &&
636 test_cmp expect actual
640 test_expect_success
'make unstaged changes in existing submodule (.M S.M.)' '
643 echo "zzzz" >>file_in_sub
646 HSUP=$(git rev-parse HEAD) &&
647 HSUB=$(cd sub1 && git rev-parse HEAD) &&
649 cat >expect <<-EOF &&
651 # branch.head initial-branch
652 # branch.upstream origin/initial-branch
654 1 .M S.M. 160000 160000 160000 $HSUB $HSUB sub1
657 git status --porcelain=v2 --branch --untracked-files=all >actual &&
658 test_cmp expect actual