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