Git 2.33.8
[git.git] / t / t7064-wtstatus-pv2.sh
blob95a9b4708378b1eb23a2e3f717e68779e8110693
1 #!/bin/sh
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
11 . ./test-lib.sh
14 test_expect_success setup '
15 git checkout -f --orphan initial-branch &&
16 test_tick &&
17 git config core.autocrlf false &&
18 echo x >file_x &&
19 echo y >file_y &&
20 echo z >file_z &&
21 mkdir dir1 &&
22 echo a >dir1/file_a &&
23 echo b >dir1/file_b
26 test_expect_success 'before initial commit, nothing added, only untracked' '
27 cat >expect <<-EOF &&
28 # branch.oid (initial)
29 # branch.head initial-branch
30 ? actual
31 ? dir1/
32 ? expect
33 ? file_x
34 ? file_y
35 ? file_z
36 EOF
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) &&
50 cat >expect <<-EOF &&
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
58 ? actual
59 ? expect
60 EOF
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
75 ? actual
76 ? expect
77 EOF
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) &&
86 cat >expect <<-EOF &&
87 # branch.oid $H0
88 # branch.head initial-branch
89 ? actual
90 ? expect
91 EOF
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' '
98 echo x >>file_x &&
99 OID_X1=$(git hash-object -t blob -- file_x) &&
100 rm file_z &&
101 H0=$(git rev-parse HEAD) &&
103 cat >expect <<-EOF &&
104 # branch.oid $H0
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
108 ? actual
109 ? expect
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' '
127 git add file_x &&
128 git rm file_z &&
129 H0=$(git rev-parse HEAD) &&
131 cat >expect <<-EOF &&
132 # branch.oid $H0
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
136 ? actual
137 ? expect
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 &&
149 # branch.oid $H0
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
154 ? actual
155 ? expect
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 &&
167 # branch.oid $H0
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
172 ? actual
173 ? expect
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 &&
185 # branch.oid $H1
186 # branch.head initial-branch
187 ? actual
188 ? expect
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 &&
201 ? .gitignore
202 ? actual
203 ? expect
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 &&
216 ? .gitignore
217 ? actual
218 ? expect
219 ! x.ign
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 &&
228 actual*
229 expect*
232 git add .gitignore &&
233 git commit -m ignore_trash &&
234 H1=$(git rev-parse HEAD) &&
236 cat >expect <<-EOF &&
237 # branch.oid $H1
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" &&
247 touch intent1.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 &&
265 git checkout AA_A &&
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 &&
272 git checkout AA_B &&
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 &&
279 git checkout AA_M &&
280 test_must_fail git merge AA_A &&
282 HM=$(git rev-parse HEAD) &&
284 cat >expect <<-EOF &&
285 # branch.oid $HM
286 # branch.head AA_M
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 &&
305 git checkout UU_A &&
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 &&
312 git checkout UU_B &&
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 &&
319 git checkout UU_M &&
320 test_must_fail git merge UU_A &&
322 HM=$(git rev-parse HEAD) &&
324 cat >expect <<-EOF &&
325 # branch.oid $HM
326 # branch.head UU_M
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.
340 cd sub_repo &&
341 HUF=$(git rev-parse HEAD) &&
343 cat >expect <<-EOF &&
344 # branch.oid $HUF
345 # branch.head initial-branch
346 # branch.upstream origin/initial-branch
347 # branch.ab +0 -0
350 git status --porcelain=v2 --branch --untracked-files=all >actual &&
351 test_cmp expect actual &&
353 ## Test ahead/behind.
354 echo xyz >file_xyz &&
355 git add file_xyz &&
356 git commit -m xyz &&
358 HUF=$(git rev-parse HEAD) &&
360 cat >expect <<-EOF &&
361 # branch.oid $HUF
362 # branch.head initial-branch
363 # branch.upstream origin/initial-branch
364 # branch.ab +1 -0
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 OLD=$(git rev-parse origin/initial-branch) &&
377 NEW=$ZERO_OID &&
378 mv .git/packed-refs .git/old-packed-refs &&
379 sed "s/$OLD/$NEW/g" <.git/old-packed-refs >.git/packed-refs &&
381 HUF=$(git rev-parse HEAD) &&
383 cat >expect <<-EOF &&
384 # branch.oid $HUF
385 # branch.head initial-branch
386 # branch.upstream origin/initial-branch
389 git status --porcelain=v2 --branch --untracked-files=all >actual &&
390 test_cmp expect actual
394 test_expect_success 'verify --[no-]ahead-behind with V2 format' '
395 git checkout initial-branch &&
396 test_when_finished "rm -rf sub_repo" &&
397 git clone . sub_repo &&
399 ## Confirm local initial-branch tracks remote initial-branch.
400 cd sub_repo &&
401 HUF=$(git rev-parse HEAD) &&
403 # Confirm --no-ahead-behind reports traditional branch.ab with 0/0 for equal branches.
404 cat >expect <<-EOF &&
405 # branch.oid $HUF
406 # branch.head initial-branch
407 # branch.upstream origin/initial-branch
408 # branch.ab +0 -0
411 git status --no-ahead-behind --porcelain=v2 --branch --untracked-files=all >actual &&
412 test_cmp expect actual &&
414 # Confirm --ahead-behind reports traditional branch.ab with 0/0.
415 cat >expect <<-EOF &&
416 # branch.oid $HUF
417 # branch.head initial-branch
418 # branch.upstream origin/initial-branch
419 # branch.ab +0 -0
422 git status --ahead-behind --porcelain=v2 --branch --untracked-files=all >actual &&
423 test_cmp expect actual &&
425 ## Test non-equal ahead/behind.
426 echo xyz >file_xyz &&
427 git add file_xyz &&
428 git commit -m xyz &&
430 HUF=$(git rev-parse HEAD) &&
432 # Confirm --no-ahead-behind reports branch.ab with ?/? for non-equal branches.
433 cat >expect <<-EOF &&
434 # branch.oid $HUF
435 # branch.head initial-branch
436 # branch.upstream origin/initial-branch
437 # branch.ab +? -?
440 git status --no-ahead-behind --porcelain=v2 --branch --untracked-files=all >actual &&
441 test_cmp expect actual &&
443 # Confirm --ahead-behind reports traditional branch.ab with 1/0.
444 cat >expect <<-EOF &&
445 # branch.oid $HUF
446 # branch.head initial-branch
447 # branch.upstream origin/initial-branch
448 # branch.ab +1 -0
451 git status --ahead-behind --porcelain=v2 --branch --untracked-files=all >actual &&
452 test_cmp expect actual &&
454 # Confirm that "status.aheadbehind" DOES NOT work on V2 format.
455 git -c status.aheadbehind=false status --porcelain=v2 --branch --untracked-files=all >actual &&
456 test_cmp expect actual &&
458 # Confirm that "status.aheadbehind" DOES NOT work on V2 format.
459 git -c status.aheadbehind=true status --porcelain=v2 --branch --untracked-files=all >actual &&
460 test_cmp expect actual
464 test_expect_success 'create and add submodule, submodule appears clean (A. S...)' '
465 git checkout initial-branch &&
466 git clone . sub_repo &&
467 git clone . super_repo &&
468 test_config_global protocol.file.allow always &&
469 ( cd super_repo &&
470 git submodule add ../sub_repo sub1 &&
472 ## Confirm stage/add of clean submodule.
473 HMOD=$(git hash-object -t blob -- .gitmodules) &&
474 HSUP=$(git rev-parse HEAD) &&
475 HSUB=$HSUP &&
477 cat >expect <<-EOF &&
478 # branch.oid $HSUP
479 # branch.head initial-branch
480 # branch.upstream origin/initial-branch
481 # branch.ab +0 -0
482 1 A. N... 000000 100644 100644 $ZERO_OID $HMOD .gitmodules
483 1 A. S... 000000 160000 160000 $ZERO_OID $HSUB sub1
486 git status --porcelain=v2 --branch --untracked-files=all >actual &&
487 test_cmp expect actual
491 test_expect_success 'untracked changes in added submodule (AM S..U)' '
492 ( cd super_repo &&
493 ## create untracked file in the submodule.
494 ( cd sub1 &&
495 echo "xxxx" >file_in_sub
496 ) &&
498 HMOD=$(git hash-object -t blob -- .gitmodules) &&
499 HSUP=$(git rev-parse HEAD) &&
500 HSUB=$HSUP &&
502 cat >expect <<-EOF &&
503 # branch.oid $HSUP
504 # branch.head initial-branch
505 # branch.upstream origin/initial-branch
506 # branch.ab +0 -0
507 1 A. N... 000000 100644 100644 $ZERO_OID $HMOD .gitmodules
508 1 AM S..U 000000 160000 160000 $ZERO_OID $HSUB sub1
511 git status --porcelain=v2 --branch --untracked-files=all >actual &&
512 test_cmp expect actual
516 test_expect_success 'staged changes in added submodule (AM S.M.)' '
517 ( cd super_repo &&
518 ## stage the changes in the submodule.
519 ( cd sub1 &&
520 git add file_in_sub
521 ) &&
523 HMOD=$(git hash-object -t blob -- .gitmodules) &&
524 HSUP=$(git rev-parse HEAD) &&
525 HSUB=$HSUP &&
527 cat >expect <<-EOF &&
528 # branch.oid $HSUP
529 # branch.head initial-branch
530 # branch.upstream origin/initial-branch
531 # branch.ab +0 -0
532 1 A. N... 000000 100644 100644 $ZERO_OID $HMOD .gitmodules
533 1 AM S.M. 000000 160000 160000 $ZERO_OID $HSUB sub1
536 git status --porcelain=v2 --branch --untracked-files=all >actual &&
537 test_cmp expect actual
541 test_expect_success 'staged and unstaged changes in added (AM S.M.)' '
542 ( cd super_repo &&
543 ( cd sub1 &&
544 ## make additional unstaged changes (on the same file) in the submodule.
545 ## This does not cause us to get S.MU (because the submodule does not report
546 ## a "?" line for the unstaged changes).
547 echo "more changes" >>file_in_sub
548 ) &&
550 HMOD=$(git hash-object -t blob -- .gitmodules) &&
551 HSUP=$(git rev-parse HEAD) &&
552 HSUB=$HSUP &&
554 cat >expect <<-EOF &&
555 # branch.oid $HSUP
556 # branch.head initial-branch
557 # branch.upstream origin/initial-branch
558 # branch.ab +0 -0
559 1 A. N... 000000 100644 100644 $ZERO_OID $HMOD .gitmodules
560 1 AM S.M. 000000 160000 160000 $ZERO_OID $HSUB sub1
563 git status --porcelain=v2 --branch --untracked-files=all >actual &&
564 test_cmp expect actual
568 test_expect_success 'staged and untracked changes in added submodule (AM S.MU)' '
569 ( cd super_repo &&
570 ( cd sub1 &&
571 ## stage new changes in tracked file.
572 git add file_in_sub &&
573 ## create new untracked file.
574 echo "yyyy" >>another_file_in_sub
575 ) &&
577 HMOD=$(git hash-object -t blob -- .gitmodules) &&
578 HSUP=$(git rev-parse HEAD) &&
579 HSUB=$HSUP &&
581 cat >expect <<-EOF &&
582 # branch.oid $HSUP
583 # branch.head initial-branch
584 # branch.upstream origin/initial-branch
585 # branch.ab +0 -0
586 1 A. N... 000000 100644 100644 $ZERO_OID $HMOD .gitmodules
587 1 AM S.MU 000000 160000 160000 $ZERO_OID $HSUB sub1
590 git status --porcelain=v2 --branch --untracked-files=all >actual &&
591 test_cmp expect actual
595 test_expect_success 'commit within the submodule appears as new commit in super (AM SC..)' '
596 ( cd super_repo &&
597 ( cd sub1 &&
598 ## Make a new commit in the submodule.
599 git add file_in_sub &&
600 rm -f another_file_in_sub &&
601 git commit -m "new commit"
602 ) &&
604 HMOD=$(git hash-object -t blob -- .gitmodules) &&
605 HSUP=$(git rev-parse HEAD) &&
606 HSUB=$HSUP &&
608 cat >expect <<-EOF &&
609 # branch.oid $HSUP
610 # branch.head initial-branch
611 # branch.upstream origin/initial-branch
612 # branch.ab +0 -0
613 1 A. N... 000000 100644 100644 $ZERO_OID $HMOD .gitmodules
614 1 AM SC.. 000000 160000 160000 $ZERO_OID $HSUB sub1
617 git status --porcelain=v2 --branch --untracked-files=all >actual &&
618 test_cmp expect actual
622 test_expect_success 'stage submodule in super and commit' '
623 ( cd super_repo &&
624 ## Stage the new submodule commit in the super.
625 git add sub1 &&
626 ## Commit the super so that the sub no longer appears as added.
627 git commit -m "super commit" &&
629 HSUP=$(git rev-parse HEAD) &&
631 cat >expect <<-EOF &&
632 # branch.oid $HSUP
633 # branch.head initial-branch
634 # branch.upstream origin/initial-branch
635 # branch.ab +1 -0
638 git status --porcelain=v2 --branch --untracked-files=all >actual &&
639 test_cmp expect actual
643 test_expect_success 'make unstaged changes in existing submodule (.M S.M.)' '
644 ( cd super_repo &&
645 ( cd sub1 &&
646 echo "zzzz" >>file_in_sub
647 ) &&
649 HSUP=$(git rev-parse HEAD) &&
650 HSUB=$(cd sub1 && git rev-parse HEAD) &&
652 cat >expect <<-EOF &&
653 # branch.oid $HSUP
654 # branch.head initial-branch
655 # branch.upstream origin/initial-branch
656 # branch.ab +1 -0
657 1 .M S.M. 160000 160000 160000 $HSUB $HSUB sub1
660 git status --porcelain=v2 --branch --untracked-files=all >actual &&
661 test_cmp expect actual
665 test_done