Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/git/blob/master/t/t7064-wtstatus-pv2.sh # git [Ported from github.com/git/git] Sync with Git 2.56.1 Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `master` Branches Tags History `git / t / t7064-wtstatus-pv2.sh` 674 lines ยท 17740 bytes Raw Blame History 1 #!/bin/sh 2 3 test_description='git status --porcelain=v2 4 5 This test exercises porcelain V2 output for git status.' 6 7 . ./test-lib.sh 8 9 10 test_expect_success setup ' 11 git checkout -f --orphan initial-branch && 12 test_tick && 13 git config core.autocrlf false && 14 echo x >file_x && 15 echo y >file_y && 16 echo z >file_z && 17 mkdir dir1 && 18 echo a >dir1/file_a && 19 echo b >dir1/file_b 20 ' 21 22 test_expect_success 'before initial commit, nothing added, only untracked' ' 23 cat >expect <<-EOF && 24 # branch.oid (initial) 25 # branch.head initial-branch 26 ? actual 27 ? dir1/ 28 ? expect 29 ? file_x 30 ? file_y 31 ? file_z 32 EOF 33 34 git status --porcelain=v2 --branch --untracked-files=normal >actual && 35 test_cmp expect actual 36 ' 37 38 test_expect_success 'before initial commit, things added' ' 39 git add file_x file_y file_z dir1 && 40 OID_A=$(git hash-object -t blob -- dir1/file_a) && 41 OID_B=$(git hash-object -t blob -- dir1/file_b) && 42 OID_X=$(git hash-object -t blob -- file_x) && 43 OID_Y=$(git hash-object -t blob -- file_y) && 44 OID_Z=$(git hash-object -t blob -- file_z) && 45 46 cat >expect <<-EOF && 47 # branch.oid (initial) 48 # branch.head initial-branch 49 1 A. N... 000000 100644 100644 $ZERO_OID $OID_A dir1/file_a 50 1 A. N... 000000 100644 100644 $ZERO_OID $OID_B dir1/file_b 51 1 A. N... 000000 100644 100644 $ZERO_OID $OID_X file_x 52 1 A. N... 000000 100644 100644 $ZERO_OID $OID_Y file_y 53 1 A. N... 000000 100644 100644 $ZERO_OID $OID_Z file_z 54 ? actual 55 ? expect 56 EOF 57 58 git status --porcelain=v2 --branch --untracked-files=all >actual && 59 test_cmp expect actual 60 ' 61 62 test_expect_success 'before initial commit, things added (-z)' ' 63 lf_to_nul >expect <<-EOF && 64 # branch.oid (initial) 65 # branch.head initial-branch 66 1 A. N... 000000 100644 100644 $ZERO_OID $OID_A dir1/file_a 67 1 A. N... 000000 100644 100644 $ZERO_OID $OID_B dir1/file_b 68 1 A. N... 000000 100644 100644 $ZERO_OID $OID_X file_x 69 1 A. N... 000000 100644 100644 $ZERO_OID $OID_Y file_y 70 1 A. N... 000000 100644 100644 $ZERO_OID $OID_Z file_z 71 ? actual 72 ? expect 73 EOF 74 75 git status -z --porcelain=v2 --branch --untracked-files=all >actual && 76 test_cmp expect actual 77 ' 78 79 test_expect_success 'make first commit, confirm HEAD oid and branch' ' 80 git commit -m initial && 81 H0=$(git rev-parse HEAD) && 82 cat >expect <<-EOF && 83 # branch.oid $H0 84 # branch.head initial-branch 85 ? actual 86 ? expect 87 EOF 88 89 git status --porcelain=v2 --branch --untracked-files=all >actual && 90 test_cmp expect actual 91 ' 92 93 test_expect_success 'after first commit, create unstaged changes' ' 94 echo x >>file_x && 95 OID_X1=$(git hash-object -t blob -- file_x) && 96 rm file_z && 97 H0=$(git rev-parse HEAD) && 98 99 cat >expect <<-EOF && 100 # branch.oid $H0 101 # branch.head initial-branch 102 1 .M N... 100644 100644 100644 $OID_X $OID_X file_x 103 1 .D N... 100644 100644 000000 $OID_Z $OID_Z file_z 104 ? actual 105 ? expect 106 EOF 107 108 git status --porcelain=v2 --branch --untracked-files=all >actual && 109 test_cmp expect actual 110 ' 111 112 test_expect_success 'after first commit, stash existing changes' ' 113 cat >expect <<-EOF && 114 # branch.oid $H0 115 # branch.head initial-branch 116 # stash 2 117 EOF 118 119 test_when_finished "git stash pop && git stash pop" && 120 121 git stash -- file_x && 122 git stash && 123 git status --porcelain=v2 --branch --show-stash --untracked-files=no >actual && 124 test_cmp expect actual 125 ' 126 127 test_expect_success 'after first commit but omit untracked files and branch' ' 128 cat >expect <<-EOF && 129 1 .M N... 100644 100644 100644 $OID_X $OID_X file_x 130 1 .D N... 100644 100644 000000 $OID_Z $OID_Z file_z 131 EOF 132 133 git status --porcelain=v2 --untracked-files=no >actual && 134 test_cmp expect actual 135 ' 136 137 test_expect_success 'after first commit, stage existing changes' ' 138 git add file_x && 139 git rm file_z && 140 H0=$(git rev-parse HEAD) && 141 142 cat >expect <<-EOF && 143 # branch.oid $H0 144 # branch.head initial-branch 145 1 M. N... 100644 100644 100644 $OID_X $OID_X1 file_x 146 1 D. N... 100644 000000 000000 $OID_Z $ZERO_OID file_z 147 ? actual 148 ? expect 149 EOF 150 151 git status --porcelain=v2 --branch --untracked-files=all >actual && 152 test_cmp expect actual 153 ' 154 155 test_expect_success 'rename causes 2 path lines' ' 156 git mv file_y renamed_y && 157 H0=$(git rev-parse HEAD) && 158 159 q_to_tab >expect <<-EOF && 160 # branch.oid $H0 161 # branch.head initial-branch 162 1 M. N... 100644 100644 100644 $OID_X $OID_X1 file_x 163 1 D. N... 100644 000000 000000 $OID_Z $ZERO_OID file_z 164 2 R. N... 100644 100644 100644 $OID_Y $OID_Y R100 renamed_yQfile_y 165 ? actual 166 ? expect 167 EOF 168 169 git status --porcelain=v2 --branch --untracked-files=all >actual && 170 test_cmp expect actual 171 ' 172 173 test_expect_success 'rename causes 2 path lines (-z)' ' 174 H0=$(git rev-parse HEAD) && 175 176 ## Lines use NUL path separator and line terminator, so double transform here. 177 q_to_nul <<-EOF | lf_to_nul >expect && 178 # branch.oid $H0 179 # branch.head initial-branch 180 1 M. N... 100644 100644 100644 $OID_X $OID_X1 file_x 181 1 D. N... 100644 000000 000000 $OID_Z $ZERO_OID file_z 182 2 R. N... 100644 100644 100644 $OID_Y $OID_Y R100 renamed_yQfile_y 183 ? actual 184 ? expect 185 EOF 186 187 git status --porcelain=v2 --branch --untracked-files=all -z >actual && 188 test_cmp expect actual 189 ' 190 191 test_expect_success 'make second commit, confirm clean and new HEAD oid' ' 192 git commit -m second && 193 H1=$(git rev-parse HEAD) && 194 195 cat >expect <<-EOF && 196 # branch.oid $H1 197 # branch.head initial-branch 198 ? actual 199 ? expect 200 EOF 201 202 git status --porcelain=v2 --branch --untracked-files=all >actual && 203 test_cmp expect actual 204 ' 205 206 test_expect_success 'confirm ignored files are not printed' ' 207 test_when_finished "rm -f x.ign .gitignore" && 208 echo x.ign >.gitignore && 209 echo "ignore me" >x.ign && 210 211 cat >expect <<-EOF && 212 ? .gitignore 213 ? actual 214 ? expect 215 EOF 216 217 git status --porcelain=v2 --untracked-files=all >actual && 218 test_cmp expect actual 219 ' 220 221 test_expect_success 'ignored files are printed with --ignored' ' 222 test_when_finished "rm -f x.ign .gitignore" && 223 echo x.ign >.gitignore && 224 echo "ignore me" >x.ign && 225 226 cat >expect <<-EOF && 227 ? .gitignore 228 ? actual 229 ? expect 230 ! x.ign 231 EOF 232 233 git status --porcelain=v2 --ignored --untracked-files=all >actual && 234 test_filter_gitconfig actual && 235 test_cmp expect actual 236 ' 237 238 test_expect_success 'create and commit permanent ignore file' ' 239 cat >.gitignore <<-EOF && 240 actual* 241 expect* 242 EOF 243 244 git add .gitignore && 245 git commit -m ignore_trash && 246 H1=$(git rev-parse HEAD) && 247 248 cat >expect <<-EOF && 249 # branch.oid $H1 250 # branch.head initial-branch 251 EOF 252 253 git status --porcelain=v2 --branch >actual && 254 test_cmp expect actual 255 ' 256 257 test_expect_success 'verify --intent-to-add output' ' 258 test_when_finished "git rm -f intent1.add intent2.add" && 259 touch intent1.add && 260 echo test >intent2.add && 261 262 git add --intent-to-add intent1.add intent2.add && 263 264 cat >expect <<-EOF && 265 1 .A N... 000000 000000 100644 $ZERO_OID $ZERO_OID intent1.add 266 1 .A N... 000000 000000 100644 $ZERO_OID $ZERO_OID intent2.add 267 EOF 268 269 git status --porcelain=v2 >actual && 270 test_cmp expect actual 271 ' 272 273 test_expect_success 'verify AA (add-add) conflict' ' 274 test_when_finished "git reset --hard" && 275 276 git branch AA_A initial-branch && 277 git checkout AA_A && 278 echo "Branch AA_A" >conflict.txt && 279 OID_AA_A=$(git hash-object -t blob -- conflict.txt) && 280 git add conflict.txt && 281 git commit -m "branch aa_a" && 282 283 git branch AA_B initial-branch && 284 git checkout AA_B && 285 echo "Branch AA_B" >conflict.txt && 286 OID_AA_B=$(git hash-object -t blob -- conflict.txt) && 287 git add conflict.txt && 288 git commit -m "branch aa_b" && 289 290 git branch AA_M AA_B && 291 git checkout AA_M && 292 test_must_fail git merge AA_A && 293 294 HM=$(git rev-parse HEAD) && 295 296 cat >expect <<-EOF && 297 # branch.oid $HM 298 # branch.head AA_M 299 u AA N... 000000 100644 100644 100644 $ZERO_OID $OID_AA_B $OID_AA_A conflict.txt 300 EOF 301 302 git status --porcelain=v2 --branch --untracked-files=all >actual && 303 test_cmp expect actual 304 ' 305 306 test_expect_success 'verify UU (edit-edit) conflict' ' 307 test_when_finished "git reset --hard" && 308 309 git branch UU_ANC initial-branch && 310 git checkout UU_ANC && 311 echo "Ancestor" >conflict.txt && 312 OID_UU_ANC=$(git hash-object -t blob -- conflict.txt) && 313 git add conflict.txt && 314 git commit -m "UU_ANC" && 315 316 git branch UU_A UU_ANC && 317 git checkout UU_A && 318 echo "Branch UU_A" >conflict.txt && 319 OID_UU_A=$(git hash-object -t blob -- conflict.txt) && 320 git add conflict.txt && 321 git commit -m "branch uu_a" && 322 323 git branch UU_B UU_ANC && 324 git checkout UU_B && 325 echo "Branch UU_B" >conflict.txt && 326 OID_UU_B=$(git hash-object -t blob -- conflict.txt) && 327 git add conflict.txt && 328 git commit -m "branch uu_b" && 329 330 git branch UU_M UU_B && 331 git checkout UU_M && 332 test_must_fail git merge UU_A && 333 334 HM=$(git rev-parse HEAD) && 335 336 cat >expect <<-EOF && 337 # branch.oid $HM 338 # branch.head UU_M 339 u UU N... 100644 100644 100644 100644 $OID_UU_ANC $OID_UU_B $OID_UU_A conflict.txt 340 EOF 341 342 git status --porcelain=v2 --branch --untracked-files=all >actual && 343 test_cmp expect actual 344 ' 345 346 test_expect_success 'verify upstream fields in branch header' ' 347 git checkout initial-branch && 348 test_when_finished "rm -rf sub_repo" && 349 git clone . sub_repo && 350 ( 351 ## Confirm local initial-branch tracks remote initial-branch. 352 cd sub_repo && 353 HUF=$(git rev-parse HEAD) && 354 355 cat >expect <<-EOF && 356 # branch.oid $HUF 357 # branch.head initial-branch 358 # branch.upstream origin/initial-branch 359 # branch.ab +0 -0 360 EOF 361 362 git status --porcelain=v2 --branch --untracked-files=all >actual && 363 test_cmp expect actual && 364 365 ## Test ahead/behind. 366 echo xyz >file_xyz && 367 git add file_xyz && 368 git commit -m xyz && 369 370 HUF=$(git rev-parse HEAD) && 371 372 cat >expect <<-EOF && 373 # branch.oid $HUF 374 # branch.head initial-branch 375 # branch.upstream origin/initial-branch 376 # branch.ab +1 -0 377 EOF 378 379 git status --porcelain=v2 --branch --untracked-files=all >actual && 380 test_cmp expect actual && 381 382 ## Repeat the above but without --branch. 383 git status --porcelain=v2 --untracked-files=all >actual && 384 test_must_be_empty actual && 385 386 ## Test upstream-gone case. Fake this by pointing 387 ## origin/initial-branch at a non-existing commit. 388 git update-ref -d refs/remotes/origin/initial-branch && 389 390 HUF=$(git rev-parse HEAD) && 391 392 cat >expect <<-EOF && 393 # branch.oid $HUF 394 # branch.head initial-branch 395 # branch.upstream origin/initial-branch 396 EOF 397 398 git status --porcelain=v2 --branch --untracked-files=all >actual && 399 test_cmp expect actual 400 ) 401 ' 402 403 test_expect_success 'verify --[no-]ahead-behind with V2 format' ' 404 git checkout initial-branch && 405 test_when_finished "rm -rf sub_repo" && 406 git clone . sub_repo && 407 ( 408 ## Confirm local initial-branch tracks remote initial-branch. 409 cd sub_repo && 410 HUF=$(git rev-parse HEAD) && 411 412 # Confirm --no-ahead-behind reports traditional branch.ab with 0/0 for equal branches. 413 cat >expect <<-EOF && 414 # branch.oid $HUF 415 # branch.head initial-branch 416 # branch.upstream origin/initial-branch 417 # branch.ab +0 -0 418 EOF 419 420 git status --no-ahead-behind --porcelain=v2 --branch --untracked-files=all >actual && 421 test_cmp expect actual && 422 423 # Confirm --ahead-behind reports traditional branch.ab with 0/0. 424 cat >expect <<-EOF && 425 # branch.oid $HUF 426 # branch.head initial-branch 427 # branch.upstream origin/initial-branch 428 # branch.ab +0 -0 429 EOF 430 431 git status --ahead-behind --porcelain=v2 --branch --untracked-files=all >actual && 432 test_cmp expect actual && 433 434 ## Test non-equal ahead/behind. 435 echo xyz >file_xyz && 436 git add file_xyz && 437 git commit -m xyz && 438 439 HUF=$(git rev-parse HEAD) && 440 441 # Confirm --no-ahead-behind reports branch.ab with ?/? for non-equal branches. 442 cat >expect <<-EOF && 443 # branch.oid $HUF 444 # branch.head initial-branch 445 # branch.upstream origin/initial-branch 446 # branch.ab +? -? 447 EOF 448 449 git status --no-ahead-behind --porcelain=v2 --branch --untracked-files=all >actual && 450 test_cmp expect actual && 451 452 # Confirm --ahead-behind reports traditional branch.ab with 1/0. 453 cat >expect <<-EOF && 454 # branch.oid $HUF 455 # branch.head initial-branch 456 # branch.upstream origin/initial-branch 457 # branch.ab +1 -0 458 EOF 459 460 git status --ahead-behind --porcelain=v2 --branch --untracked-files=all >actual && 461 test_cmp expect actual && 462 463 # Confirm that "status.aheadbehind" DOES NOT work on V2 format. 464 git -c status.aheadbehind=false status --porcelain=v2 --branch --untracked-files=all >actual && 465 test_cmp expect actual && 466 467 # Confirm that "status.aheadbehind" DOES NOT work on V2 format. 468 git -c status.aheadbehind=true status --porcelain=v2 --branch --untracked-files=all >actual && 469 test_cmp expect actual 470 ) 471 ' 472 473 test_expect_success 'create and add submodule, submodule appears clean (A. S...)' ' 474 git checkout initial-branch && 475 git clone . sub_repo && 476 git clone . super_repo && 477 test_config_global protocol.file.allow always && 478 ( cd super_repo && 479 git submodule add ../sub_repo sub1 && 480 481 ## Confirm stage/add of clean submodule. 482 HMOD=$(git hash-object -t blob -- .gitmodules) && 483 HSUP=$(git rev-parse HEAD) && 484 HSUB=$HSUP && 485 486 cat >expect <<-EOF && 487 # branch.oid $HSUP 488 # branch.head initial-branch 489 # branch.upstream origin/initial-branch 490 # branch.ab +0 -0 491 1 A. N... 000000 100644 100644 $ZERO_OID $HMOD .gitmodules 492 1 A. S... 000000 160000 160000 $ZERO_OID $HSUB sub1 493 EOF 494 495 git status --porcelain=v2 --branch --untracked-files=all >actual && 496 test_cmp expect actual 497 ) 498 ' 499 500 test_expect_success 'untracked changes in added submodule (AM S..U)' ' 501 ( cd super_repo && 502 ## create untracked file in the submodule. 503 ( cd sub1 && 504 echo "xxxx" >file_in_sub 505 ) && 506 507 HMOD=$(git hash-object -t blob -- .gitmodules) && 508 HSUP=$(git rev-parse HEAD) && 509 HSUB=$HSUP && 510 511 cat >expect <<-EOF && 512 # branch.oid $HSUP 513 # branch.head initial-branch 514 # branch.upstream origin/initial-branch 515 # branch.ab +0 -0 516 1 A. N... 000000 100644 100644 $ZERO_OID $HMOD .gitmodules 517 1 AM S..U 000000 160000 160000 $ZERO_OID $HSUB sub1 518 EOF 519 520 git status --porcelain=v2 --branch --untracked-files=all >actual && 521 test_cmp expect actual 522 ) 523 ' 524 525 test_expect_success 'staged changes in added submodule (AM S.M.)' ' 526 ( cd super_repo && 527 ## stage the changes in the submodule. 528 ( cd sub1 && 529 git add file_in_sub 530 ) && 531 532 HMOD=$(git hash-object -t blob -- .gitmodules) && 533 HSUP=$(git rev-parse HEAD) && 534 HSUB=$HSUP && 535 536 cat >expect <<-EOF && 537 # branch.oid $HSUP 538 # branch.head initial-branch 539 # branch.upstream origin/initial-branch 540 # branch.ab +0 -0 541 1 A. N... 000000 100644 100644 $ZERO_OID $HMOD .gitmodules 542 1 AM S.M. 000000 160000 160000 $ZERO_OID $HSUB sub1 543 EOF 544 545 git status --porcelain=v2 --branch --untracked-files=all >actual && 546 test_cmp expect actual 547 ) 548 ' 549 550 test_expect_success 'staged and unstaged changes in added (AM S.M.)' ' 551 ( cd super_repo && 552 ( cd sub1 && 553 ## make additional unstaged changes (on the same file) in the submodule. 554 ## This does not cause us to get S.MU (because the submodule does not report 555 ## a "?" line for the unstaged changes). 556 echo "more changes" >>file_in_sub 557 ) && 558 559 HMOD=$(git hash-object -t blob -- .gitmodules) && 560 HSUP=$(git rev-parse HEAD) && 561 HSUB=$HSUP && 562 563 cat >expect <<-EOF && 564 # branch.oid $HSUP 565 # branch.head initial-branch 566 # branch.upstream origin/initial-branch 567 # branch.ab +0 -0 568 1 A. N... 000000 100644 100644 $ZERO_OID $HMOD .gitmodules 569 1 AM S.M. 000000 160000 160000 $ZERO_OID $HSUB sub1 570 EOF 571 572 git status --porcelain=v2 --branch --untracked-files=all >actual && 573 test_cmp expect actual 574 ) 575 ' 576 577 test_expect_success 'staged and untracked changes in added submodule (AM S.MU)' ' 578 ( cd super_repo && 579 ( cd sub1 && 580 ## stage new changes in tracked file. 581 git add file_in_sub && 582 ## create new untracked file. 583 echo "yyyy" >>another_file_in_sub 584 ) && 585 586 HMOD=$(git hash-object -t blob -- .gitmodules) && 587 HSUP=$(git rev-parse HEAD) && 588 HSUB=$HSUP && 589 590 cat >expect <<-EOF && 591 # branch.oid $HSUP 592 # branch.head initial-branch 593 # branch.upstream origin/initial-branch 594 # branch.ab +0 -0 595 1 A. N... 000000 100644 100644 $ZERO_OID $HMOD .gitmodules 596 1 AM S.MU 000000 160000 160000 $ZERO_OID $HSUB sub1 597 EOF 598 599 git status --porcelain=v2 --branch --untracked-files=all >actual && 600 test_cmp expect actual 601 ) 602 ' 603 604 test_expect_success 'commit within the submodule appears as new commit in super (AM SC..)' ' 605 ( cd super_repo && 606 ( cd sub1 && 607 ## Make a new commit in the submodule. 608 git add file_in_sub && 609 rm -f another_file_in_sub && 610 git commit -m "new commit" 611 ) && 612 613 HMOD=$(git hash-object -t blob -- .gitmodules) && 614 HSUP=$(git rev-parse HEAD) && 615 HSUB=$HSUP && 616 617 cat >expect <<-EOF && 618 # branch.oid $HSUP 619 # branch.head initial-branch 620 # branch.upstream origin/initial-branch 621 # branch.ab +0 -0 622 1 A. N... 000000 100644 100644 $ZERO_OID $HMOD .gitmodules 623 1 AM SC.. 000000 160000 160000 $ZERO_OID $HSUB sub1 624 EOF 625 626 git status --porcelain=v2 --branch --untracked-files=all >actual && 627 test_cmp expect actual 628 ) 629 ' 630 631 test_expect_success 'stage submodule in super and commit' ' 632 ( cd super_repo && 633 ## Stage the new submodule commit in the super. 634 git add sub1 && 635 ## Commit the super so that the sub no longer appears as added. 636 git commit -m "super commit" && 637 638 HSUP=$(git rev-parse HEAD) && 639 640 cat >expect <<-EOF && 641 # branch.oid $HSUP 642 # branch.head initial-branch 643 # branch.upstream origin/initial-branch 644 # branch.ab +1 -0 645 EOF 646 647 git status --porcelain=v2 --branch --untracked-files=all >actual && 648 test_cmp expect actual 649 ) 650 ' 651 652 test_expect_success 'make unstaged changes in existing submodule (.M S.M.)' ' 653 ( cd super_repo && 654 ( cd sub1 && 655 echo "zzzz" >>file_in_sub 656 ) && 657 658 HSUP=$(git rev-parse HEAD) && 659 HSUB=$(cd sub1 && git rev-parse HEAD) && 660 661 cat >expect <<-EOF && 662 # branch.oid $HSUP 663 # branch.head initial-branch 664 # branch.upstream origin/initial-branch 665 # branch.ab +1 -0 666 1 .M S.M. 160000 160000 160000 $HSUB $HSUB sub1 667 EOF 668 669 git status --porcelain=v2 --branch --untracked-files=all >actual && 670 test_cmp expect actual 671 ) 672 ' 673 674 test_done