Git fork
at reftables-rust 1064 lines 36 kB view raw
1#!/bin/sh 2# 3# Copyright (c) 2012 Valentin Duperray, Lucien Kong, Franck Jonas, 4# Thomas Nguy, Khoi Nguyen 5# Grenoble INP Ensimag 6# 7 8test_description='git status advice' 9 10GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main 11export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME 12 13. ./test-lib.sh 14 15. "$TEST_DIRECTORY"/lib-rebase.sh 16 17set_fake_editor 18 19test_expect_success 'prepare for conflicts' ' 20 git config --global advice.statusuoption false && 21 test_commit init main.txt init && 22 git branch conflicts && 23 test_commit on_main main.txt on_main && 24 git checkout conflicts && 25 test_commit on_conflicts main.txt on_conflicts 26' 27 28 29test_expect_success 'status when conflicts unresolved' ' 30 test_must_fail git merge main && 31 cat >expected <<\EOF && 32On branch conflicts 33You have unmerged paths. 34 (fix conflicts and run "git commit") 35 (use "git merge --abort" to abort the merge) 36 37Unmerged paths: 38 (use "git add <file>..." to mark resolution) 39 both modified: main.txt 40 41no changes added to commit (use "git add" and/or "git commit -a") 42EOF 43 git status --untracked-files=no >actual && 44 test_cmp expected actual 45' 46 47 48test_expect_success 'status when conflicts resolved before commit' ' 49 git reset --hard conflicts && 50 test_must_fail git merge main && 51 echo one >main.txt && 52 git add main.txt && 53 cat >expected <<\EOF && 54On branch conflicts 55All conflicts fixed but you are still merging. 56 (use "git commit" to conclude merge) 57 58Changes to be committed: 59 modified: main.txt 60 61Untracked files not listed (use -u option to show untracked files) 62EOF 63 git status --untracked-files=no >actual && 64 test_cmp expected actual 65' 66 67 68test_expect_success 'prepare for rebase conflicts' ' 69 git reset --hard main && 70 git checkout -b rebase_conflicts && 71 test_commit one_rebase main.txt one && 72 test_commit two_rebase main.txt two && 73 test_commit three_rebase main.txt three 74' 75 76 77test_expect_success 'status when rebase --apply in progress before resolving conflicts' ' 78 test_when_finished "git rebase --abort" && 79 ONTO=$(git rev-parse --short HEAD^^) && 80 test_must_fail git rebase --apply HEAD^ --onto HEAD^^ && 81 cat >expected <<EOF && 82rebase in progress; onto $ONTO 83You are currently rebasing branch '\''rebase_conflicts'\'' on '\''$ONTO'\''. 84 (fix conflicts and then run "git rebase --continue") 85 (use "git rebase --skip" to skip this patch) 86 (use "git rebase --abort" to check out the original branch) 87 88Unmerged paths: 89 (use "git restore --staged <file>..." to unstage) 90 (use "git add <file>..." to mark resolution) 91 both modified: main.txt 92 93no changes added to commit (use "git add" and/or "git commit -a") 94EOF 95 git status --untracked-files=no >actual && 96 test_cmp expected actual 97' 98 99 100test_expect_success 'status when rebase --apply in progress before rebase --continue' ' 101 git reset --hard rebase_conflicts && 102 test_when_finished "git rebase --abort" && 103 ONTO=$(git rev-parse --short HEAD^^) && 104 test_must_fail git rebase --apply HEAD^ --onto HEAD^^ && 105 echo three >main.txt && 106 git add main.txt && 107 cat >expected <<EOF && 108rebase in progress; onto $ONTO 109You are currently rebasing branch '\''rebase_conflicts'\'' on '\''$ONTO'\''. 110 (all conflicts fixed: run "git rebase --continue") 111 112Changes to be committed: 113 (use "git restore --staged <file>..." to unstage) 114 modified: main.txt 115 116Untracked files not listed (use -u option to show untracked files) 117EOF 118 git status --untracked-files=no >actual && 119 test_cmp expected actual 120' 121 122 123test_expect_success 'prepare for rebase_i_conflicts' ' 124 git reset --hard main && 125 git checkout -b rebase_i_conflicts && 126 test_commit one_unmerge main.txt one_unmerge && 127 git branch rebase_i_conflicts_second && 128 test_commit one_main main.txt one_main && 129 git checkout rebase_i_conflicts_second && 130 test_commit one_second main.txt one_second 131' 132 133 134test_expect_success 'status during rebase -i when conflicts unresolved' ' 135 test_when_finished "git rebase --abort" && 136 ONTO=$(git rev-parse --short rebase_i_conflicts) && 137 LAST_COMMIT=$(git rev-parse --short rebase_i_conflicts_second) && 138 test_must_fail git rebase -i rebase_i_conflicts && 139 cat >expected <<EOF && 140interactive rebase in progress; onto $ONTO 141Last command done (1 command done): 142 pick $LAST_COMMIT # one_second 143No commands remaining. 144You are currently rebasing branch '\''rebase_i_conflicts_second'\'' on '\''$ONTO'\''. 145 (fix conflicts and then run "git rebase --continue") 146 (use "git rebase --skip" to skip this patch) 147 (use "git rebase --abort" to check out the original branch) 148 149Unmerged paths: 150 (use "git restore --staged <file>..." to unstage) 151 (use "git add <file>..." to mark resolution) 152 both modified: main.txt 153 154no changes added to commit (use "git add" and/or "git commit -a") 155EOF 156 git status --untracked-files=no >actual && 157 test_cmp expected actual 158' 159 160 161test_expect_success 'status during rebase -i after resolving conflicts' ' 162 git reset --hard rebase_i_conflicts_second && 163 test_when_finished "git rebase --abort" && 164 ONTO=$(git rev-parse --short rebase_i_conflicts) && 165 LAST_COMMIT=$(git rev-parse --short rebase_i_conflicts_second) && 166 test_must_fail git rebase -i rebase_i_conflicts && 167 git add main.txt && 168 cat >expected <<EOF && 169interactive rebase in progress; onto $ONTO 170Last command done (1 command done): 171 pick $LAST_COMMIT # one_second 172No commands remaining. 173You are currently rebasing branch '\''rebase_i_conflicts_second'\'' on '\''$ONTO'\''. 174 (all conflicts fixed: run "git rebase --continue") 175 176Changes to be committed: 177 (use "git restore --staged <file>..." to unstage) 178 modified: main.txt 179 180Untracked files not listed (use -u option to show untracked files) 181EOF 182 git status --untracked-files=no >actual && 183 test_cmp expected actual 184' 185 186 187test_expect_success 'status when rebasing -i in edit mode' ' 188 git reset --hard main && 189 git checkout -b rebase_i_edit && 190 test_commit one_rebase_i main.txt one && 191 test_commit two_rebase_i main.txt two && 192 COMMIT2=$(git rev-parse --short rebase_i_edit) && 193 test_commit three_rebase_i main.txt three && 194 COMMIT3=$(git rev-parse --short rebase_i_edit) && 195 FAKE_LINES="1 edit 2" && 196 export FAKE_LINES && 197 test_when_finished "git rebase --abort" && 198 ONTO=$(git rev-parse --short HEAD~2) && 199 git rebase -i HEAD~2 && 200 cat >expected <<EOF && 201interactive rebase in progress; onto $ONTO 202Last commands done (2 commands done): 203 pick $COMMIT2 # two_rebase_i 204 edit $COMMIT3 # three_rebase_i 205No commands remaining. 206You are currently editing a commit while rebasing branch '\''rebase_i_edit'\'' on '\''$ONTO'\''. 207 (use "git commit --amend" to amend the current commit) 208 (use "git rebase --continue" once you are satisfied with your changes) 209 210nothing to commit (use -u to show untracked files) 211EOF 212 git status --untracked-files=no >actual && 213 test_cmp expected actual 214' 215 216 217test_expect_success 'status when splitting a commit' ' 218 git reset --hard main && 219 git checkout -b split_commit && 220 test_commit one_split main.txt one && 221 test_commit two_split main.txt two && 222 COMMIT2=$(git rev-parse --short split_commit) && 223 test_commit three_split main.txt three && 224 COMMIT3=$(git rev-parse --short split_commit) && 225 test_commit four_split main.txt four && 226 COMMIT4=$(git rev-parse --short split_commit) && 227 FAKE_LINES="1 edit 2 3" && 228 export FAKE_LINES && 229 test_when_finished "git rebase --abort" && 230 ONTO=$(git rev-parse --short HEAD~3) && 231 git rebase -i HEAD~3 && 232 git reset HEAD^ && 233 cat >expected <<EOF && 234interactive rebase in progress; onto $ONTO 235Last commands done (2 commands done): 236 pick $COMMIT2 # two_split 237 edit $COMMIT3 # three_split 238Next command to do (1 remaining command): 239 pick $COMMIT4 # four_split 240 (use "git rebase --edit-todo" to view and edit) 241You are currently splitting a commit while rebasing branch '\''split_commit'\'' on '\''$ONTO'\''. 242 (Once your working directory is clean, run "git rebase --continue") 243 244Changes not staged for commit: 245 (use "git add <file>..." to update what will be committed) 246 (use "git restore <file>..." to discard changes in working directory) 247 modified: main.txt 248 249no changes added to commit (use "git add" and/or "git commit -a") 250EOF 251 git status --untracked-files=no >actual && 252 test_cmp expected actual 253' 254 255 256test_expect_success 'status after editing the last commit with --amend during a rebase -i' ' 257 git reset --hard main && 258 git checkout -b amend_last && 259 test_commit one_amend main.txt one && 260 test_commit two_amend main.txt two && 261 test_commit three_amend main.txt three && 262 COMMIT3=$(git rev-parse --short amend_last) && 263 test_commit four_amend main.txt four && 264 COMMIT4=$(git rev-parse --short amend_last) && 265 FAKE_LINES="1 2 edit 3" && 266 export FAKE_LINES && 267 test_when_finished "git rebase --abort" && 268 ONTO=$(git rev-parse --short HEAD~3) && 269 git rebase -i HEAD~3 && 270 git commit --amend -m "foo" && 271 cat >expected <<EOF && 272interactive rebase in progress; onto $ONTO 273Last commands done (3 commands done): 274 pick $COMMIT3 # three_amend 275 edit $COMMIT4 # four_amend 276 (see more in file .git/rebase-merge/done) 277No commands remaining. 278You are currently editing a commit while rebasing branch '\''amend_last'\'' on '\''$ONTO'\''. 279 (use "git commit --amend" to amend the current commit) 280 (use "git rebase --continue" once you are satisfied with your changes) 281 282nothing to commit (use -u to show untracked files) 283EOF 284 git status --untracked-files=no >actual && 285 test_cmp expected actual 286' 287 288 289test_expect_success 'prepare for several edits' ' 290 git reset --hard main && 291 git checkout -b several_edits && 292 test_commit one_edits main.txt one && 293 test_commit two_edits main.txt two && 294 test_commit three_edits main.txt three && 295 test_commit four_edits main.txt four 296' 297 298 299test_expect_success 'status: (continue first edit) second edit' ' 300 FAKE_LINES="edit 1 edit 2 3" && 301 export FAKE_LINES && 302 test_when_finished "git rebase --abort" && 303 COMMIT2=$(git rev-parse --short several_edits^^) && 304 COMMIT3=$(git rev-parse --short several_edits^) && 305 COMMIT4=$(git rev-parse --short several_edits) && 306 ONTO=$(git rev-parse --short HEAD~3) && 307 git rebase -i HEAD~3 && 308 git rebase --continue && 309 cat >expected <<EOF && 310interactive rebase in progress; onto $ONTO 311Last commands done (2 commands done): 312 edit $COMMIT2 # two_edits 313 edit $COMMIT3 # three_edits 314Next command to do (1 remaining command): 315 pick $COMMIT4 # four_edits 316 (use "git rebase --edit-todo" to view and edit) 317You are currently editing a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''. 318 (use "git commit --amend" to amend the current commit) 319 (use "git rebase --continue" once you are satisfied with your changes) 320 321nothing to commit (use -u to show untracked files) 322EOF 323 git status --untracked-files=no >actual && 324 test_cmp expected actual 325' 326 327 328test_expect_success 'status: (continue first edit) second edit and split' ' 329 git reset --hard several_edits && 330 FAKE_LINES="edit 1 edit 2 3" && 331 export FAKE_LINES && 332 test_when_finished "git rebase --abort" && 333 COMMIT2=$(git rev-parse --short several_edits^^) && 334 COMMIT3=$(git rev-parse --short several_edits^) && 335 COMMIT4=$(git rev-parse --short several_edits) && 336 ONTO=$(git rev-parse --short HEAD~3) && 337 git rebase -i HEAD~3 && 338 git rebase --continue && 339 git reset HEAD^ && 340 cat >expected <<EOF && 341interactive rebase in progress; onto $ONTO 342Last commands done (2 commands done): 343 edit $COMMIT2 # two_edits 344 edit $COMMIT3 # three_edits 345Next command to do (1 remaining command): 346 pick $COMMIT4 # four_edits 347 (use "git rebase --edit-todo" to view and edit) 348You are currently splitting a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''. 349 (Once your working directory is clean, run "git rebase --continue") 350 351Changes not staged for commit: 352 (use "git add <file>..." to update what will be committed) 353 (use "git restore <file>..." to discard changes in working directory) 354 modified: main.txt 355 356no changes added to commit (use "git add" and/or "git commit -a") 357EOF 358 git status --untracked-files=no >actual && 359 test_cmp expected actual 360' 361 362 363test_expect_success 'status: (continue first edit) second edit and amend' ' 364 git reset --hard several_edits && 365 FAKE_LINES="edit 1 edit 2 3" && 366 export FAKE_LINES && 367 test_when_finished "git rebase --abort" && 368 COMMIT2=$(git rev-parse --short several_edits^^) && 369 COMMIT3=$(git rev-parse --short several_edits^) && 370 COMMIT4=$(git rev-parse --short several_edits) && 371 ONTO=$(git rev-parse --short HEAD~3) && 372 git rebase -i HEAD~3 && 373 git rebase --continue && 374 git commit --amend -m "foo" && 375 cat >expected <<EOF && 376interactive rebase in progress; onto $ONTO 377Last commands done (2 commands done): 378 edit $COMMIT2 # two_edits 379 edit $COMMIT3 # three_edits 380Next command to do (1 remaining command): 381 pick $COMMIT4 # four_edits 382 (use "git rebase --edit-todo" to view and edit) 383You are currently editing a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''. 384 (use "git commit --amend" to amend the current commit) 385 (use "git rebase --continue" once you are satisfied with your changes) 386 387nothing to commit (use -u to show untracked files) 388EOF 389 git status --untracked-files=no >actual && 390 test_cmp expected actual 391' 392 393 394test_expect_success 'status: (amend first edit) second edit' ' 395 git reset --hard several_edits && 396 FAKE_LINES="edit 1 edit 2 3" && 397 export FAKE_LINES && 398 test_when_finished "git rebase --abort" && 399 COMMIT2=$(git rev-parse --short several_edits^^) && 400 COMMIT3=$(git rev-parse --short several_edits^) && 401 COMMIT4=$(git rev-parse --short several_edits) && 402 ONTO=$(git rev-parse --short HEAD~3) && 403 git rebase -i HEAD~3 && 404 git commit --amend -m "a" && 405 git rebase --continue && 406 cat >expected <<EOF && 407interactive rebase in progress; onto $ONTO 408Last commands done (2 commands done): 409 edit $COMMIT2 # two_edits 410 edit $COMMIT3 # three_edits 411Next command to do (1 remaining command): 412 pick $COMMIT4 # four_edits 413 (use "git rebase --edit-todo" to view and edit) 414You are currently editing a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''. 415 (use "git commit --amend" to amend the current commit) 416 (use "git rebase --continue" once you are satisfied with your changes) 417 418nothing to commit (use -u to show untracked files) 419EOF 420 git status --untracked-files=no >actual && 421 test_cmp expected actual 422' 423 424 425test_expect_success 'status: (amend first edit) second edit and split' ' 426 git reset --hard several_edits && 427 FAKE_LINES="edit 1 edit 2 3" && 428 export FAKE_LINES && 429 test_when_finished "git rebase --abort" && 430 ONTO=$(git rev-parse --short HEAD~3) && 431 COMMIT2=$(git rev-parse --short several_edits^^) && 432 COMMIT3=$(git rev-parse --short several_edits^) && 433 COMMIT4=$(git rev-parse --short several_edits) && 434 git rebase -i HEAD~3 && 435 git commit --amend -m "b" && 436 git rebase --continue && 437 git reset HEAD^ && 438 cat >expected <<EOF && 439interactive rebase in progress; onto $ONTO 440Last commands done (2 commands done): 441 edit $COMMIT2 # two_edits 442 edit $COMMIT3 # three_edits 443Next command to do (1 remaining command): 444 pick $COMMIT4 # four_edits 445 (use "git rebase --edit-todo" to view and edit) 446You are currently splitting a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''. 447 (Once your working directory is clean, run "git rebase --continue") 448 449Changes not staged for commit: 450 (use "git add <file>..." to update what will be committed) 451 (use "git restore <file>..." to discard changes in working directory) 452 modified: main.txt 453 454no changes added to commit (use "git add" and/or "git commit -a") 455EOF 456 git status --untracked-files=no >actual && 457 test_cmp expected actual 458' 459 460 461test_expect_success 'status: (amend first edit) second edit and amend' ' 462 git reset --hard several_edits && 463 FAKE_LINES="edit 1 edit 2 3" && 464 export FAKE_LINES && 465 test_when_finished "git rebase --abort" && 466 COMMIT2=$(git rev-parse --short several_edits^^) && 467 COMMIT3=$(git rev-parse --short several_edits^) && 468 COMMIT4=$(git rev-parse --short several_edits) && 469 ONTO=$(git rev-parse --short HEAD~3) && 470 git rebase -i HEAD~3 && 471 git commit --amend -m "c" && 472 git rebase --continue && 473 git commit --amend -m "d" && 474 cat >expected <<EOF && 475interactive rebase in progress; onto $ONTO 476Last commands done (2 commands done): 477 edit $COMMIT2 # two_edits 478 edit $COMMIT3 # three_edits 479Next command to do (1 remaining command): 480 pick $COMMIT4 # four_edits 481 (use "git rebase --edit-todo" to view and edit) 482You are currently editing a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''. 483 (use "git commit --amend" to amend the current commit) 484 (use "git rebase --continue" once you are satisfied with your changes) 485 486nothing to commit (use -u to show untracked files) 487EOF 488 git status --untracked-files=no >actual && 489 test_cmp expected actual 490' 491 492 493test_expect_success 'status: (split first edit) second edit' ' 494 git reset --hard several_edits && 495 FAKE_LINES="edit 1 edit 2 3" && 496 export FAKE_LINES && 497 test_when_finished "git rebase --abort" && 498 COMMIT2=$(git rev-parse --short several_edits^^) && 499 COMMIT3=$(git rev-parse --short several_edits^) && 500 COMMIT4=$(git rev-parse --short several_edits) && 501 ONTO=$(git rev-parse --short HEAD~3) && 502 git rebase -i HEAD~3 && 503 git reset HEAD^ && 504 git add main.txt && 505 git commit -m "e" && 506 git rebase --continue && 507 cat >expected <<EOF && 508interactive rebase in progress; onto $ONTO 509Last commands done (2 commands done): 510 edit $COMMIT2 # two_edits 511 edit $COMMIT3 # three_edits 512Next command to do (1 remaining command): 513 pick $COMMIT4 # four_edits 514 (use "git rebase --edit-todo" to view and edit) 515You are currently editing a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''. 516 (use "git commit --amend" to amend the current commit) 517 (use "git rebase --continue" once you are satisfied with your changes) 518 519nothing to commit (use -u to show untracked files) 520EOF 521 git status --untracked-files=no >actual && 522 test_cmp expected actual 523' 524 525 526test_expect_success 'status: (split first edit) second edit and split' ' 527 git reset --hard several_edits && 528 FAKE_LINES="edit 1 edit 2 3" && 529 export FAKE_LINES && 530 test_when_finished "git rebase --abort" && 531 COMMIT2=$(git rev-parse --short several_edits^^) && 532 COMMIT3=$(git rev-parse --short several_edits^) && 533 COMMIT4=$(git rev-parse --short several_edits) && 534 ONTO=$(git rev-parse --short HEAD~3) && 535 git rebase -i HEAD~3 && 536 git reset HEAD^ && 537 git add main.txt && 538 git commit --amend -m "f" && 539 git rebase --continue && 540 git reset HEAD^ && 541 cat >expected <<EOF && 542interactive rebase in progress; onto $ONTO 543Last commands done (2 commands done): 544 edit $COMMIT2 # two_edits 545 edit $COMMIT3 # three_edits 546Next command to do (1 remaining command): 547 pick $COMMIT4 # four_edits 548 (use "git rebase --edit-todo" to view and edit) 549You are currently splitting a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''. 550 (Once your working directory is clean, run "git rebase --continue") 551 552Changes not staged for commit: 553 (use "git add <file>..." to update what will be committed) 554 (use "git restore <file>..." to discard changes in working directory) 555 modified: main.txt 556 557no changes added to commit (use "git add" and/or "git commit -a") 558EOF 559 git status --untracked-files=no >actual && 560 test_cmp expected actual 561' 562 563 564test_expect_success 'status: (split first edit) second edit and amend' ' 565 git reset --hard several_edits && 566 FAKE_LINES="edit 1 edit 2 3" && 567 export FAKE_LINES && 568 test_when_finished "git rebase --abort" && 569 COMMIT2=$(git rev-parse --short several_edits^^) && 570 COMMIT3=$(git rev-parse --short several_edits^) && 571 COMMIT4=$(git rev-parse --short several_edits) && 572 ONTO=$(git rev-parse --short HEAD~3) && 573 git rebase -i HEAD~3 && 574 git reset HEAD^ && 575 git add main.txt && 576 git commit --amend -m "g" && 577 git rebase --continue && 578 git commit --amend -m "h" && 579 cat >expected <<EOF && 580interactive rebase in progress; onto $ONTO 581Last commands done (2 commands done): 582 edit $COMMIT2 # two_edits 583 edit $COMMIT3 # three_edits 584Next command to do (1 remaining command): 585 pick $COMMIT4 # four_edits 586 (use "git rebase --edit-todo" to view and edit) 587You are currently editing a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''. 588 (use "git commit --amend" to amend the current commit) 589 (use "git rebase --continue" once you are satisfied with your changes) 590 591nothing to commit (use -u to show untracked files) 592EOF 593 git status --untracked-files=no >actual && 594 test_cmp expected actual 595' 596 597 598test_expect_success 'prepare am_session' ' 599 git reset --hard main && 600 git checkout -b am_session && 601 test_commit one_am one.txt "one" && 602 test_commit two_am two.txt "two" && 603 test_commit three_am three.txt "three" 604' 605 606 607test_expect_success 'status in an am session: file already exists' ' 608 git checkout -b am_already_exists && 609 test_when_finished "rm Maildir/* && git am --abort" && 610 git format-patch -1 -oMaildir && 611 test_must_fail git am Maildir/*.patch && 612 cat >expected <<\EOF && 613On branch am_already_exists 614You are in the middle of an am session. 615 (fix conflicts and then run "git am --continue") 616 (use "git am --skip" to skip this patch) 617 (use "git am --abort" to restore the original branch) 618 619nothing to commit (use -u to show untracked files) 620EOF 621 git status --untracked-files=no >actual && 622 test_cmp expected actual 623' 624 625 626test_expect_success 'status in an am session: file does not exist' ' 627 git reset --hard am_session && 628 git checkout -b am_not_exists && 629 git rm three.txt && 630 git commit -m "delete three.txt" && 631 test_when_finished "rm Maildir/* && git am --abort" && 632 git format-patch -1 -oMaildir && 633 test_must_fail git am Maildir/*.patch && 634 cat >expected <<\EOF && 635On branch am_not_exists 636You are in the middle of an am session. 637 (fix conflicts and then run "git am --continue") 638 (use "git am --skip" to skip this patch) 639 (use "git am --abort" to restore the original branch) 640 641nothing to commit (use -u to show untracked files) 642EOF 643 git status --untracked-files=no >actual && 644 test_cmp expected actual 645' 646 647 648test_expect_success 'status in an am session: empty patch' ' 649 git reset --hard am_session && 650 git checkout -b am_empty && 651 test_when_finished "rm Maildir/* && git am --abort" && 652 git format-patch -3 -oMaildir && 653 git rm one.txt two.txt three.txt && 654 git commit -m "delete all am_empty" && 655 echo error >Maildir/0002-two_am.patch && 656 test_must_fail git am Maildir/*.patch && 657 cat >expected <<\EOF && 658On branch am_empty 659You are in the middle of an am session. 660The current patch is empty. 661 (use "git am --skip" to skip this patch) 662 (use "git am --allow-empty" to record this patch as an empty commit) 663 (use "git am --abort" to restore the original branch) 664 665nothing to commit (use -u to show untracked files) 666EOF 667 git status --untracked-files=no >actual && 668 test_cmp expected actual 669' 670 671 672test_expect_success 'status when bisecting' ' 673 git reset --hard main && 674 git checkout -b bisect && 675 test_commit one_bisect main.txt one && 676 test_commit two_bisect main.txt two && 677 test_commit three_bisect main.txt three && 678 test_when_finished "git bisect reset" && 679 git bisect start && 680 git bisect bad && 681 git bisect good one_bisect && 682 TGT=$(git rev-parse --short two_bisect) && 683 cat >expected <<EOF && 684HEAD detached at $TGT 685You are currently bisecting, started from branch '\''bisect'\''. 686 (use "git bisect reset" to get back to the original branch) 687 688nothing to commit (use -u to show untracked files) 689EOF 690 git status --untracked-files=no >actual && 691 test_cmp expected actual 692' 693 694 695test_expect_success 'status when bisecting while rebasing' ' 696 git reset --hard main && 697 test_when_finished "git rebase --abort" && 698 ONTO=$(git rev-parse --short HEAD^) && 699 FAKE_LINES="break" git rebase -i HEAD^ && 700 test_when_finished "git checkout -" && 701 git checkout -b bisect_while_rebasing && 702 test_when_finished "git bisect reset" && 703 git bisect start && 704 cat >expected <<EOF && 705On branch bisect_while_rebasing 706Last command done (1 command done): 707 break 708No commands remaining. 709You are currently editing a commit while rebasing branch '\''bisect'\'' on '\''$ONTO'\''. 710 (use "git commit --amend" to amend the current commit) 711 (use "git rebase --continue" once you are satisfied with your changes) 712 713You are currently bisecting, started from branch '\''bisect_while_rebasing'\''. 714 (use "git bisect reset" to get back to the original branch) 715 716nothing to commit (use -u to show untracked files) 717EOF 718 git status --untracked-files=no >actual && 719 test_cmp expected actual 720' 721 722 723test_expect_success 'status when rebase --apply conflicts with statushints disabled' ' 724 git reset --hard main && 725 git checkout -b statushints_disabled && 726 test_when_finished "git config --local advice.statushints true" && 727 git config --local advice.statushints false && 728 test_commit one_statushints main.txt one && 729 test_commit two_statushints main.txt two && 730 test_commit three_statushints main.txt three && 731 test_when_finished "git rebase --abort" && 732 ONTO=$(git rev-parse --short HEAD^^) && 733 test_must_fail git rebase --apply HEAD^ --onto HEAD^^ && 734 cat >expected <<EOF && 735rebase in progress; onto $ONTO 736You are currently rebasing branch '\''statushints_disabled'\'' on '\''$ONTO'\''. 737 738Unmerged paths: 739 both modified: main.txt 740 741no changes added to commit 742EOF 743 git status --untracked-files=no >actual && 744 test_cmp expected actual 745' 746 747 748test_expect_success 'prepare for cherry-pick conflicts' ' 749 git reset --hard main && 750 git checkout -b cherry_branch && 751 test_commit one_cherry main.txt one && 752 test_commit two_cherries main.txt two && 753 git checkout -b cherry_branch_second && 754 test_commit second_cherry main.txt second && 755 git checkout cherry_branch && 756 test_commit three_cherries main.txt three 757' 758 759 760test_expect_success 'status when cherry-picking before resolving conflicts' ' 761 test_when_finished "git cherry-pick --abort" && 762 test_must_fail git cherry-pick cherry_branch_second && 763 TO_CHERRY_PICK=$(git rev-parse --short CHERRY_PICK_HEAD) && 764 cat >expected <<EOF && 765On branch cherry_branch 766You are currently cherry-picking commit $TO_CHERRY_PICK. 767 (fix conflicts and run "git cherry-pick --continue") 768 (use "git cherry-pick --skip" to skip this patch) 769 (use "git cherry-pick --abort" to cancel the cherry-pick operation) 770 771Unmerged paths: 772 (use "git add <file>..." to mark resolution) 773 both modified: main.txt 774 775no changes added to commit (use "git add" and/or "git commit -a") 776EOF 777 git status --untracked-files=no >actual && 778 test_cmp expected actual 779' 780 781 782test_expect_success 'status when cherry-picking after resolving conflicts' ' 783 git reset --hard cherry_branch && 784 test_when_finished "git cherry-pick --abort" && 785 test_must_fail git cherry-pick cherry_branch_second && 786 TO_CHERRY_PICK=$(git rev-parse --short CHERRY_PICK_HEAD) && 787 echo end >main.txt && 788 git add main.txt && 789 cat >expected <<EOF && 790On branch cherry_branch 791You are currently cherry-picking commit $TO_CHERRY_PICK. 792 (all conflicts fixed: run "git cherry-pick --continue") 793 (use "git cherry-pick --skip" to skip this patch) 794 (use "git cherry-pick --abort" to cancel the cherry-pick operation) 795 796Changes to be committed: 797 modified: main.txt 798 799Untracked files not listed (use -u option to show untracked files) 800EOF 801 git status --untracked-files=no >actual && 802 test_cmp expected actual 803' 804 805test_expect_success 'status when cherry-picking multiple commits' ' 806 git reset --hard cherry_branch && 807 test_when_finished "git cherry-pick --abort" && 808 test_must_fail git cherry-pick cherry_branch_second one_cherry && 809 TO_CHERRY_PICK=$(git rev-parse --short CHERRY_PICK_HEAD) && 810 cat >expected <<EOF && 811On branch cherry_branch 812You are currently cherry-picking commit $TO_CHERRY_PICK. 813 (fix conflicts and run "git cherry-pick --continue") 814 (use "git cherry-pick --skip" to skip this patch) 815 (use "git cherry-pick --abort" to cancel the cherry-pick operation) 816 817Unmerged paths: 818 (use "git add <file>..." to mark resolution) 819 both modified: main.txt 820 821no changes added to commit (use "git add" and/or "git commit -a") 822EOF 823 git status --untracked-files=no >actual && 824 test_cmp expected actual 825' 826 827test_expect_success 'status when cherry-picking after committing conflict resolution' ' 828 git reset --hard cherry_branch && 829 test_when_finished "git cherry-pick --abort" && 830 test_must_fail git cherry-pick cherry_branch_second one_cherry && 831 echo end >main.txt && 832 git commit -a && 833 cat >expected <<EOF && 834On branch cherry_branch 835Cherry-pick currently in progress. 836 (run "git cherry-pick --continue" to continue) 837 (use "git cherry-pick --skip" to skip this patch) 838 (use "git cherry-pick --abort" to cancel the cherry-pick operation) 839 840nothing to commit (use -u to show untracked files) 841EOF 842 git status --untracked-files=no >actual && 843 test_cmp expected actual 844' 845 846test_expect_success 'status shows cherry-pick with invalid oid' ' 847 mkdir .git/sequencer && 848 test_write_lines "pick invalid-oid" >.git/sequencer/todo && 849 git status --untracked-files=no >actual 2>err && 850 git cherry-pick --quit && 851 test_must_be_empty err && 852 test_cmp expected actual 853' 854 855test_expect_success 'status does not show error if .git/sequencer is a file' ' 856 test_when_finished "rm .git/sequencer" && 857 test_write_lines hello >.git/sequencer && 858 git status --untracked-files=no 2>err && 859 test_must_be_empty err 860' 861 862test_expect_success 'status showing detached at and from a tag' ' 863 test_commit atag tagging && 864 git checkout atag && 865 cat >expected <<\EOF && 866HEAD detached at atag 867nothing to commit (use -u to show untracked files) 868EOF 869 git status --untracked-files=no >actual && 870 test_cmp expected actual && 871 872 git reset --hard HEAD^ && 873 cat >expected <<\EOF && 874HEAD detached from atag 875nothing to commit (use -u to show untracked files) 876EOF 877 git status --untracked-files=no >actual && 878 test_cmp expected actual 879' 880 881test_expect_success 'status while reverting commit (conflicts)' ' 882 git checkout main && 883 echo before >to-revert.txt && 884 test_commit before to-revert.txt && 885 echo old >to-revert.txt && 886 test_commit old to-revert.txt && 887 echo new >to-revert.txt && 888 test_commit new to-revert.txt && 889 TO_REVERT=$(git rev-parse --short HEAD^) && 890 test_must_fail git revert $TO_REVERT && 891 cat >expected <<EOF && 892On branch main 893You are currently reverting commit $TO_REVERT. 894 (fix conflicts and run "git revert --continue") 895 (use "git revert --skip" to skip this patch) 896 (use "git revert --abort" to cancel the revert operation) 897 898Unmerged paths: 899 (use "git restore --staged <file>..." to unstage) 900 (use "git add <file>..." to mark resolution) 901 both modified: to-revert.txt 902 903no changes added to commit (use "git add" and/or "git commit -a") 904EOF 905 git status --untracked-files=no >actual && 906 test_cmp expected actual 907' 908 909test_expect_success 'status while reverting commit (conflicts resolved)' ' 910 echo reverted >to-revert.txt && 911 git add to-revert.txt && 912 cat >expected <<EOF && 913On branch main 914You are currently reverting commit $TO_REVERT. 915 (all conflicts fixed: run "git revert --continue") 916 (use "git revert --skip" to skip this patch) 917 (use "git revert --abort" to cancel the revert operation) 918 919Changes to be committed: 920 (use "git restore --staged <file>..." to unstage) 921 modified: to-revert.txt 922 923Untracked files not listed (use -u option to show untracked files) 924EOF 925 git status --untracked-files=no >actual && 926 test_cmp expected actual 927' 928 929test_expect_success 'status after reverting commit' ' 930 git revert --continue && 931 cat >expected <<\EOF && 932On branch main 933nothing to commit (use -u to show untracked files) 934EOF 935 git status --untracked-files=no >actual && 936 test_cmp expected actual 937' 938 939test_expect_success 'status while reverting after committing conflict resolution' ' 940 test_when_finished "git revert --abort" && 941 git reset --hard new && 942 test_must_fail git revert old new && 943 echo reverted >to-revert.txt && 944 git commit -a && 945 cat >expected <<EOF && 946On branch main 947Revert currently in progress. 948 (run "git revert --continue" to continue) 949 (use "git revert --skip" to skip this patch) 950 (use "git revert --abort" to cancel the revert operation) 951 952nothing to commit (use -u to show untracked files) 953EOF 954 git status --untracked-files=no >actual && 955 test_cmp expected actual 956' 957 958test_expect_success 'prepare for different number of commits rebased' ' 959 git reset --hard main && 960 git checkout -b several_commits && 961 test_commit one_commit main.txt one && 962 test_commit two_commit main.txt two && 963 test_commit three_commit main.txt three && 964 test_commit four_commit main.txt four 965' 966 967test_expect_success 'status: one command done nothing remaining' ' 968 FAKE_LINES="exec_exit_15" && 969 export FAKE_LINES && 970 test_when_finished "git rebase --abort" && 971 ONTO=$(git rev-parse --short HEAD~3) && 972 test_must_fail git rebase -i HEAD~3 && 973 cat >expected <<EOF && 974interactive rebase in progress; onto $ONTO 975Last command done (1 command done): 976 exec exit 15 977No commands remaining. 978You are currently editing a commit while rebasing branch '\''several_commits'\'' on '\''$ONTO'\''. 979 (use "git commit --amend" to amend the current commit) 980 (use "git rebase --continue" once you are satisfied with your changes) 981 982nothing to commit (use -u to show untracked files) 983EOF 984 git status --untracked-files=no >actual && 985 test_cmp expected actual 986' 987 988test_expect_success 'status: two commands done with some white lines in done file' ' 989 FAKE_LINES="1 > exec_exit_15 2 3" && 990 export FAKE_LINES && 991 test_when_finished "git rebase --abort" && 992 ONTO=$(git rev-parse --short HEAD~3) && 993 COMMIT4=$(git rev-parse --short HEAD) && 994 COMMIT3=$(git rev-parse --short HEAD^) && 995 COMMIT2=$(git rev-parse --short HEAD^^) && 996 test_must_fail git rebase -i HEAD~3 && 997 cat >expected <<EOF && 998interactive rebase in progress; onto $ONTO 999Last commands done (2 commands done): 1000 pick $COMMIT2 # two_commit 1001 exec exit 15 1002Next commands to do (2 remaining commands): 1003 pick $COMMIT3 # three_commit 1004 pick $COMMIT4 # four_commit 1005 (use "git rebase --edit-todo" to view and edit) 1006You are currently editing a commit while rebasing branch '\''several_commits'\'' on '\''$ONTO'\''. 1007 (use "git commit --amend" to amend the current commit) 1008 (use "git rebase --continue" once you are satisfied with your changes) 1009 1010nothing to commit (use -u to show untracked files) 1011EOF 1012 git status --untracked-files=no >actual && 1013 test_cmp expected actual 1014' 1015 1016test_expect_success 'status: two remaining commands with some white lines in todo file' ' 1017 FAKE_LINES="1 2 exec_exit_15 3 > 4" && 1018 export FAKE_LINES && 1019 test_when_finished "git rebase --abort" && 1020 ONTO=$(git rev-parse --short HEAD~4) && 1021 COMMIT4=$(git rev-parse --short HEAD) && 1022 COMMIT3=$(git rev-parse --short HEAD^) && 1023 COMMIT2=$(git rev-parse --short HEAD^^) && 1024 test_must_fail git rebase -i HEAD~4 && 1025 cat >expected <<EOF && 1026interactive rebase in progress; onto $ONTO 1027Last commands done (3 commands done): 1028 pick $COMMIT2 # two_commit 1029 exec exit 15 1030 (see more in file .git/rebase-merge/done) 1031Next commands to do (2 remaining commands): 1032 pick $COMMIT3 # three_commit 1033 pick $COMMIT4 # four_commit 1034 (use "git rebase --edit-todo" to view and edit) 1035You are currently editing a commit while rebasing branch '\''several_commits'\'' on '\''$ONTO'\''. 1036 (use "git commit --amend" to amend the current commit) 1037 (use "git rebase --continue" once you are satisfied with your changes) 1038 1039nothing to commit (use -u to show untracked files) 1040EOF 1041 git status --untracked-files=no >actual && 1042 test_cmp expected actual 1043' 1044 1045test_expect_success 'status: handle not-yet-started rebase -i gracefully' ' 1046 ONTO=$(git rev-parse --short HEAD^) && 1047 COMMIT=$(git rev-parse --short HEAD) && 1048 EDITOR="git status --untracked-files=no >actual" git rebase -i HEAD^ && 1049 cat >expected <<EOF && 1050On branch several_commits 1051No commands done. 1052Next command to do (1 remaining command): 1053 pick $COMMIT # four_commit 1054 (use "git rebase --edit-todo" to view and edit) 1055You are currently editing a commit while rebasing branch '\''several_commits'\'' on '\''$ONTO'\''. 1056 (use "git commit --amend" to amend the current commit) 1057 (use "git rebase --continue" once you are satisfied with your changes) 1058 1059nothing to commit (use -u to show untracked files) 1060EOF 1061 test_cmp expected actual 1062' 1063 1064test_done