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
'
15 git checkout -f --orphan initial-branch &&
17 git config core.autocrlf false &&
22 echo a >dir1/file_a &&
26 test_expect_success
'before initial commit, nothing added, only untracked' '
28 # branch.oid (initial)
29 # branch.head initial-branch
38 git status --porcelain=v2 --branch --untracked-files=normal >actual &&
39 test_cmp expect actual
42 test_expect_success
'before initial commit, things added' '
43 git add file_x file_y file_z dir1 &&
44 OID_A=$(git hash-object -t blob -- dir1/file_a) &&
45 OID_B=$(git hash-object -t blob -- dir1/file_b) &&
46 OID_X=$(git hash-object -t blob -- file_x) &&
47 OID_Y=$(git hash-object -t blob -- file_y) &&
48 OID_Z=$(git hash-object -t blob -- file_z) &&
51 # branch.oid (initial)
52 # branch.head initial-branch
53 1 A. N... 000000 100644 100644 $ZERO_OID $OID_A dir1/file_a
54 1 A. N... 000000 100644 100644 $ZERO_OID $OID_B dir1/file_b
55 1 A. N... 000000 100644 100644 $ZERO_OID $OID_X file_x
56 1 A. N... 000000 100644 100644 $ZERO_OID $OID_Y file_y
57 1 A. N... 000000 100644 100644 $ZERO_OID $OID_Z file_z
62 git status --porcelain=v2 --branch --untracked-files=all >actual &&
63 test_cmp expect actual
66 test_expect_success
'before initial commit, things added (-z)' '
67 lf_to_nul >expect <<-EOF &&
68 # branch.oid (initial)
69 # branch.head initial-branch
70 1 A. N... 000000 100644 100644 $ZERO_OID $OID_A dir1/file_a
71 1 A. N... 000000 100644 100644 $ZERO_OID $OID_B dir1/file_b
72 1 A. N... 000000 100644 100644 $ZERO_OID $OID_X file_x
73 1 A. N... 000000 100644 100644 $ZERO_OID $OID_Y file_y
74 1 A. N... 000000 100644 100644 $ZERO_OID $OID_Z file_z
79 git status -z --porcelain=v2 --branch --untracked-files=all >actual &&
80 test_cmp expect actual
83 test_expect_success
'make first commit, comfirm HEAD oid and branch' '
84 git commit -m initial &&
85 H0=$(git rev-parse HEAD) &&
88 # branch.head initial-branch
93 git status --porcelain=v2 --branch --untracked-files=all >actual &&
94 test_cmp expect actual
97 test_expect_success
'after first commit, create unstaged changes' '
99 OID_X1=$(git hash-object -t blob -- file_x) &&
101 H0=$(git rev-parse HEAD) &&
103 cat >expect <<-EOF &&
105 # branch.head initial-branch
106 1 .M N... 100644 100644 100644 $OID_X $OID_X file_x
107 1 .D N... 100644 100644 000000 $OID_Z $OID_Z file_z
112 git status --porcelain=v2 --branch --untracked-files=all >actual &&
113 test_cmp expect actual
116 test_expect_success
'after first commit but omit untracked files and branch' '
117 cat >expect <<-EOF &&
118 1 .M N... 100644 100644 100644 $OID_X $OID_X file_x
119 1 .D N... 100644 100644 000000 $OID_Z $OID_Z file_z
122 git status --porcelain=v2 --untracked-files=no >actual &&
123 test_cmp expect actual
126 test_expect_success
'after first commit, stage existing changes' '
129 H0=$(git rev-parse HEAD) &&
131 cat >expect <<-EOF &&
133 # branch.head initial-branch
134 1 M. N... 100644 100644 100644 $OID_X $OID_X1 file_x
135 1 D. N... 100644 000000 000000 $OID_Z $ZERO_OID file_z
140 git status --porcelain=v2 --branch --untracked-files=all >actual &&
141 test_cmp expect actual
144 test_expect_success
'rename causes 2 path lines' '
145 git mv file_y renamed_y &&
146 H0=$(git rev-parse HEAD) &&
148 q_to_tab >expect <<-EOF &&
150 # branch.head initial-branch
151 1 M. N... 100644 100644 100644 $OID_X $OID_X1 file_x
152 1 D. N... 100644 000000 000000 $OID_Z $ZERO_OID file_z
153 2 R. N... 100644 100644 100644 $OID_Y $OID_Y R100 renamed_yQfile_y
158 git status --porcelain=v2 --branch --untracked-files=all >actual &&
159 test_cmp expect actual
162 test_expect_success
'rename causes 2 path lines (-z)' '
163 H0=$(git rev-parse HEAD) &&
165 ## Lines use NUL path separator and line terminator, so double transform here.
166 q_to_nul <<-EOF | lf_to_nul >expect &&
168 # branch.head initial-branch
169 1 M. N... 100644 100644 100644 $OID_X $OID_X1 file_x
170 1 D. N... 100644 000000 000000 $OID_Z $ZERO_OID file_z
171 2 R. N... 100644 100644 100644 $OID_Y $OID_Y R100 renamed_yQfile_y
176 git status --porcelain=v2 --branch --untracked-files=all -z >actual &&
177 test_cmp expect actual
180 test_expect_success
'make second commit, confirm clean and new HEAD oid' '
181 git commit -m second &&
182 H1=$(git rev-parse HEAD) &&
184 cat >expect <<-EOF &&
186 # branch.head initial-branch
191 git status --porcelain=v2 --branch --untracked-files=all >actual &&
192 test_cmp expect actual
195 test_expect_success
'confirm ignored files are not printed' '
196 test_when_finished "rm -f x.ign .gitignore" &&
197 echo x.ign >.gitignore &&
198 echo "ignore me" >x.ign &&
200 cat >expect <<-EOF &&
206 git status --porcelain=v2 --untracked-files=all >actual &&
207 test_cmp expect actual
210 test_expect_success
'ignored files are printed with --ignored' '
211 test_when_finished "rm -f x.ign .gitignore" &&
212 echo x.ign >.gitignore &&
213 echo "ignore me" >x.ign &&
215 cat >expect <<-EOF &&
222 git status --porcelain=v2 --ignored --untracked-files=all >actual &&
223 test_cmp expect actual
226 test_expect_success
'create and commit permanent ignore file' '
227 cat >.gitignore <<-EOF &&
232 git add .gitignore &&
233 git commit -m ignore_trash &&
234 H1=$(git rev-parse HEAD) &&
236 cat >expect <<-EOF &&
238 # branch.head initial-branch
241 git status --porcelain=v2 --branch >actual &&
242 test_cmp expect actual
245 test_expect_success
'verify --intent-to-add output' '
246 test_when_finished "git rm -f intent1.add intent2.add" &&
248 echo test >intent2.add &&
250 git add --intent-to-add intent1.add intent2.add &&
252 cat >expect <<-EOF &&
253 1 .A N... 000000 000000 100644 $ZERO_OID $ZERO_OID intent1.add
254 1 .A N... 000000 000000 100644 $ZERO_OID $ZERO_OID intent2.add
257 git status --porcelain=v2 >actual &&
258 test_cmp expect actual
261 test_expect_success
'verify AA (add-add) conflict' '
262 test_when_finished "git reset --hard" &&
264 git branch AA_A initial-branch &&
266 echo "Branch AA_A" >conflict.txt &&
267 OID_AA_A=$(git hash-object -t blob -- conflict.txt) &&
268 git add conflict.txt &&
269 git commit -m "branch aa_a" &&
271 git branch AA_B initial-branch &&
273 echo "Branch AA_B" >conflict.txt &&
274 OID_AA_B=$(git hash-object -t blob -- conflict.txt) &&
275 git add conflict.txt &&
276 git commit -m "branch aa_b" &&
278 git branch AA_M AA_B &&
280 test_must_fail git merge AA_A &&
282 HM=$(git rev-parse HEAD) &&
284 cat >expect <<-EOF &&
287 u AA N... 000000 100644 100644 100644 $ZERO_OID $OID_AA_B $OID_AA_A conflict.txt
290 git status --porcelain=v2 --branch --untracked-files=all >actual &&
291 test_cmp expect actual
294 test_expect_success
'verify UU (edit-edit) conflict' '
295 test_when_finished "git reset --hard" &&
297 git branch UU_ANC initial-branch &&
298 git checkout UU_ANC &&
299 echo "Ancestor" >conflict.txt &&
300 OID_UU_ANC=$(git hash-object -t blob -- conflict.txt) &&
301 git add conflict.txt &&
302 git commit -m "UU_ANC" &&
304 git branch UU_A UU_ANC &&
306 echo "Branch UU_A" >conflict.txt &&
307 OID_UU_A=$(git hash-object -t blob -- conflict.txt) &&
308 git add conflict.txt &&
309 git commit -m "branch uu_a" &&
311 git branch UU_B UU_ANC &&
313 echo "Branch UU_B" >conflict.txt &&
314 OID_UU_B=$(git hash-object -t blob -- conflict.txt) &&
315 git add conflict.txt &&
316 git commit -m "branch uu_b" &&
318 git branch UU_M UU_B &&
320 test_must_fail git merge UU_A &&
322 HM=$(git rev-parse HEAD) &&
324 cat >expect <<-EOF &&
327 u UU N... 100644 100644 100644 100644 $OID_UU_ANC $OID_UU_B $OID_UU_A conflict.txt
330 git status --porcelain=v2 --branch --untracked-files=all >actual &&
331 test_cmp expect actual
334 test_expect_success
'verify upstream fields in branch header' '
335 git checkout initial-branch &&
336 test_when_finished "rm -rf sub_repo" &&
337 git clone . sub_repo &&
339 ## Confirm local initial-branch tracks remote initial-branch.
341 HUF=$(git rev-parse HEAD) &&
343 cat >expect <<-EOF &&
345 # branch.head initial-branch
346 # branch.upstream origin/initial-branch
350 git status --porcelain=v2 --branch --untracked-files=all >actual &&
351 test_cmp expect actual &&
353 ## Test ahead/behind.
354 echo xyz >file_xyz &&
358 HUF=$(git rev-parse HEAD) &&
360 cat >expect <<-EOF &&
362 # branch.head initial-branch
363 # branch.upstream origin/initial-branch
367 git status --porcelain=v2 --branch --untracked-files=all >actual &&
368 test_cmp expect actual &&
370 ## Repeat the above but without --branch.
371 git status --porcelain=v2 --untracked-files=all >actual &&
372 test_must_be_empty actual &&
374 ## Test upstream-gone case. Fake this by pointing
375 ## origin/initial-branch at a non-existing commit.
376 git update-ref -d refs/remotes/origin/initial-branch &&
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 &&
466 git submodule add ../sub_repo sub1 &&
468 ## Confirm stage/add of clean submodule.
469 HMOD=$(git hash-object -t blob -- .gitmodules) &&
470 HSUP=$(git rev-parse HEAD) &&
473 cat >expect <<-EOF &&
475 # branch.head initial-branch
476 # branch.upstream origin/initial-branch
478 1 A. N... 000000 100644 100644 $ZERO_OID $HMOD .gitmodules
479 1 A. S... 000000 160000 160000 $ZERO_OID $HSUB sub1
482 git status --porcelain=v2 --branch --untracked-files=all >actual &&
483 test_cmp expect actual
487 test_expect_success
'untracked changes in added submodule (AM S..U)' '
489 ## create untracked file in the submodule.
491 echo "xxxx" >file_in_sub
494 HMOD=$(git hash-object -t blob -- .gitmodules) &&
495 HSUP=$(git rev-parse HEAD) &&
498 cat >expect <<-EOF &&
500 # branch.head initial-branch
501 # branch.upstream origin/initial-branch
503 1 A. N... 000000 100644 100644 $ZERO_OID $HMOD .gitmodules
504 1 AM S..U 000000 160000 160000 $ZERO_OID $HSUB sub1
507 git status --porcelain=v2 --branch --untracked-files=all >actual &&
508 test_cmp expect actual
512 test_expect_success
'staged changes in added submodule (AM S.M.)' '
514 ## stage the changes in the submodule.
519 HMOD=$(git hash-object -t blob -- .gitmodules) &&
520 HSUP=$(git rev-parse HEAD) &&
523 cat >expect <<-EOF &&
525 # branch.head initial-branch
526 # branch.upstream origin/initial-branch
528 1 A. N... 000000 100644 100644 $ZERO_OID $HMOD .gitmodules
529 1 AM S.M. 000000 160000 160000 $ZERO_OID $HSUB sub1
532 git status --porcelain=v2 --branch --untracked-files=all >actual &&
533 test_cmp expect actual
537 test_expect_success
'staged and unstaged changes in added (AM S.M.)' '
540 ## make additional unstaged changes (on the same file) in the submodule.
541 ## This does not cause us to get S.MU (because the submodule does not report
542 ## a "?" line for the unstaged changes).
543 echo "more changes" >>file_in_sub
546 HMOD=$(git hash-object -t blob -- .gitmodules) &&
547 HSUP=$(git rev-parse HEAD) &&
550 cat >expect <<-EOF &&
552 # branch.head initial-branch
553 # branch.upstream origin/initial-branch
555 1 A. N... 000000 100644 100644 $ZERO_OID $HMOD .gitmodules
556 1 AM S.M. 000000 160000 160000 $ZERO_OID $HSUB sub1
559 git status --porcelain=v2 --branch --untracked-files=all >actual &&
560 test_cmp expect actual
564 test_expect_success
'staged and untracked changes in added submodule (AM S.MU)' '
567 ## stage new changes in tracked file.
568 git add file_in_sub &&
569 ## create new untracked file.
570 echo "yyyy" >>another_file_in_sub
573 HMOD=$(git hash-object -t blob -- .gitmodules) &&
574 HSUP=$(git rev-parse HEAD) &&
577 cat >expect <<-EOF &&
579 # branch.head initial-branch
580 # branch.upstream origin/initial-branch
582 1 A. N... 000000 100644 100644 $ZERO_OID $HMOD .gitmodules
583 1 AM S.MU 000000 160000 160000 $ZERO_OID $HSUB sub1
586 git status --porcelain=v2 --branch --untracked-files=all >actual &&
587 test_cmp expect actual
591 test_expect_success
'commit within the submodule appears as new commit in super (AM SC..)' '
594 ## Make a new commit in the submodule.
595 git add file_in_sub &&
596 rm -f another_file_in_sub &&
597 git commit -m "new commit"
600 HMOD=$(git hash-object -t blob -- .gitmodules) &&
601 HSUP=$(git rev-parse HEAD) &&
604 cat >expect <<-EOF &&
606 # branch.head initial-branch
607 # branch.upstream origin/initial-branch
609 1 A. N... 000000 100644 100644 $ZERO_OID $HMOD .gitmodules
610 1 AM SC.. 000000 160000 160000 $ZERO_OID $HSUB sub1
613 git status --porcelain=v2 --branch --untracked-files=all >actual &&
614 test_cmp expect actual
618 test_expect_success
'stage submodule in super and commit' '
620 ## Stage the new submodule commit in the super.
622 ## Commit the super so that the sub no longer appears as added.
623 git commit -m "super commit" &&
625 HSUP=$(git rev-parse HEAD) &&
627 cat >expect <<-EOF &&
629 # branch.head initial-branch
630 # branch.upstream origin/initial-branch
634 git status --porcelain=v2 --branch --untracked-files=all >actual &&
635 test_cmp expect actual
639 test_expect_success
'make unstaged changes in existing submodule (.M S.M.)' '
642 echo "zzzz" >>file_in_sub
645 HSUP=$(git rev-parse HEAD) &&
646 HSUB=$(cd sub1 && git rev-parse HEAD) &&
648 cat >expect <<-EOF &&
650 # branch.head initial-branch
651 # branch.upstream origin/initial-branch
653 1 .M S.M. 160000 160000 160000 $HSUB $HSUB sub1
656 git status --porcelain=v2 --branch --untracked-files=all >actual &&
657 test_cmp expect actual