utf8: fix overflow when returning string width
[alt-git.git] / t / t7064-wtstatus-pv2.sh
blob2fdb6ecc172cf36a569c02b44cd136941f34684e
1 #!/bin/sh
3 test_description='git status --porcelain=v2
5 This test exercises porcelain V2 output for git status.'
8 . ./test-lib.sh
11 test_expect_success setup '
12 git checkout -f --orphan initial-branch &&
13 test_tick &&
14 git config core.autocrlf false &&
15 echo x >file_x &&
16 echo y >file_y &&
17 echo z >file_z &&
18 mkdir dir1 &&
19 echo a >dir1/file_a &&
20 echo b >dir1/file_b
23 test_expect_success 'before initial commit, nothing added, only untracked' '
24 cat >expect <<-EOF &&
25 # branch.oid (initial)
26 # branch.head initial-branch
27 ? actual
28 ? dir1/
29 ? expect
30 ? file_x
31 ? file_y
32 ? file_z
33 EOF
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) &&
47 cat >expect <<-EOF &&
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
55 ? actual
56 ? expect
57 EOF
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
72 ? actual
73 ? expect
74 EOF
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) &&
83 cat >expect <<-EOF &&
84 # branch.oid $H0
85 # branch.head initial-branch
86 ? actual
87 ? expect
88 EOF
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' '
95 echo x >>file_x &&
96 OID_X1=$(git hash-object -t blob -- file_x) &&
97 rm file_z &&
98 H0=$(git rev-parse HEAD) &&
100 cat >expect <<-EOF &&
101 # branch.oid $H0
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
105 ? actual
106 ? expect
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' '
124 git add file_x &&
125 git rm file_z &&
126 H0=$(git rev-parse HEAD) &&
128 cat >expect <<-EOF &&
129 # branch.oid $H0
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
133 ? actual
134 ? expect
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 &&
146 # branch.oid $H0
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
151 ? actual
152 ? expect
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 &&
164 # branch.oid $H0
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
169 ? actual
170 ? expect
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 &&
182 # branch.oid $H1
183 # branch.head initial-branch
184 ? actual
185 ? expect
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 &&
198 ? .gitignore
199 ? actual
200 ? expect
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 &&
213 ? .gitignore
214 ? actual
215 ? expect
216 ! x.ign
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 &&
225 actual*
226 expect*
229 git add .gitignore &&
230 git commit -m ignore_trash &&
231 H1=$(git rev-parse HEAD) &&
233 cat >expect <<-EOF &&
234 # branch.oid $H1
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" &&
244 touch intent1.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 &&
262 git checkout AA_A &&
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 &&
269 git checkout AA_B &&
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 &&
276 git checkout AA_M &&
277 test_must_fail git merge AA_A &&
279 HM=$(git rev-parse HEAD) &&
281 cat >expect <<-EOF &&
282 # branch.oid $HM
283 # branch.head AA_M
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 &&
302 git checkout UU_A &&
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 &&
309 git checkout UU_B &&
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 &&
316 git checkout UU_M &&
317 test_must_fail git merge UU_A &&
319 HM=$(git rev-parse HEAD) &&
321 cat >expect <<-EOF &&
322 # branch.oid $HM
323 # branch.head UU_M
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.
337 cd sub_repo &&
338 HUF=$(git rev-parse HEAD) &&
340 cat >expect <<-EOF &&
341 # branch.oid $HUF
342 # branch.head initial-branch
343 # branch.upstream origin/initial-branch
344 # branch.ab +0 -0
347 git status --porcelain=v2 --branch --untracked-files=all >actual &&
348 test_cmp expect actual &&
350 ## Test ahead/behind.
351 echo xyz >file_xyz &&
352 git add file_xyz &&
353 git commit -m xyz &&
355 HUF=$(git rev-parse HEAD) &&
357 cat >expect <<-EOF &&
358 # branch.oid $HUF
359 # branch.head initial-branch
360 # branch.upstream origin/initial-branch
361 # branch.ab +1 -0
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) &&
374 NEW=$ZERO_OID &&
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 &&
381 # branch.oid $HUF
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.
397 cd sub_repo &&
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 &&
402 # branch.oid $HUF
403 # branch.head initial-branch
404 # branch.upstream origin/initial-branch
405 # branch.ab +0 -0
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 &&
413 # branch.oid $HUF
414 # branch.head initial-branch
415 # branch.upstream origin/initial-branch
416 # branch.ab +0 -0
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 &&
424 git add file_xyz &&
425 git commit -m xyz &&
427 HUF=$(git rev-parse HEAD) &&
429 # Confirm --no-ahead-behind reports branch.ab with ?/? for non-equal branches.
430 cat >expect <<-EOF &&
431 # branch.oid $HUF
432 # branch.head initial-branch
433 # branch.upstream origin/initial-branch
434 # branch.ab +? -?
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 &&
442 # branch.oid $HUF
443 # branch.head initial-branch
444 # branch.upstream origin/initial-branch
445 # branch.ab +1 -0
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 &&
466 ( cd super_repo &&
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) &&
472 HSUB=$HSUP &&
474 cat >expect <<-EOF &&
475 # branch.oid $HSUP
476 # branch.head initial-branch
477 # branch.upstream origin/initial-branch
478 # branch.ab +0 -0
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)' '
489 ( cd super_repo &&
490 ## create untracked file in the submodule.
491 ( cd sub1 &&
492 echo "xxxx" >file_in_sub
493 ) &&
495 HMOD=$(git hash-object -t blob -- .gitmodules) &&
496 HSUP=$(git rev-parse HEAD) &&
497 HSUB=$HSUP &&
499 cat >expect <<-EOF &&
500 # branch.oid $HSUP
501 # branch.head initial-branch
502 # branch.upstream origin/initial-branch
503 # branch.ab +0 -0
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.)' '
514 ( cd super_repo &&
515 ## stage the changes in the submodule.
516 ( cd sub1 &&
517 git add file_in_sub
518 ) &&
520 HMOD=$(git hash-object -t blob -- .gitmodules) &&
521 HSUP=$(git rev-parse HEAD) &&
522 HSUB=$HSUP &&
524 cat >expect <<-EOF &&
525 # branch.oid $HSUP
526 # branch.head initial-branch
527 # branch.upstream origin/initial-branch
528 # branch.ab +0 -0
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.)' '
539 ( cd super_repo &&
540 ( cd sub1 &&
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
545 ) &&
547 HMOD=$(git hash-object -t blob -- .gitmodules) &&
548 HSUP=$(git rev-parse HEAD) &&
549 HSUB=$HSUP &&
551 cat >expect <<-EOF &&
552 # branch.oid $HSUP
553 # branch.head initial-branch
554 # branch.upstream origin/initial-branch
555 # branch.ab +0 -0
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)' '
566 ( cd super_repo &&
567 ( cd sub1 &&
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
572 ) &&
574 HMOD=$(git hash-object -t blob -- .gitmodules) &&
575 HSUP=$(git rev-parse HEAD) &&
576 HSUB=$HSUP &&
578 cat >expect <<-EOF &&
579 # branch.oid $HSUP
580 # branch.head initial-branch
581 # branch.upstream origin/initial-branch
582 # branch.ab +0 -0
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..)' '
593 ( cd super_repo &&
594 ( cd sub1 &&
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"
599 ) &&
601 HMOD=$(git hash-object -t blob -- .gitmodules) &&
602 HSUP=$(git rev-parse HEAD) &&
603 HSUB=$HSUP &&
605 cat >expect <<-EOF &&
606 # branch.oid $HSUP
607 # branch.head initial-branch
608 # branch.upstream origin/initial-branch
609 # branch.ab +0 -0
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' '
620 ( cd super_repo &&
621 ## Stage the new submodule commit in the super.
622 git add sub1 &&
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 &&
629 # branch.oid $HSUP
630 # branch.head initial-branch
631 # branch.upstream origin/initial-branch
632 # branch.ab +1 -0
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.)' '
641 ( cd super_repo &&
642 ( cd sub1 &&
643 echo "zzzz" >>file_in_sub
644 ) &&
646 HSUP=$(git rev-parse HEAD) &&
647 HSUB=$(cd sub1 && git rev-parse HEAD) &&
649 cat >expect <<-EOF &&
650 # branch.oid $HSUP
651 # branch.head initial-branch
652 # branch.upstream origin/initial-branch
653 # branch.ab +1 -0
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
662 test_done