3714e8e9c20ea3de6df102798459bf48696c2853
   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 advices'
   9
  10. ./test-lib.sh
  11
  12. "$TEST_DIRECTORY"/lib-rebase.sh
  13
  14set_fake_editor
  15
  16test_expect_success 'prepare for conflicts' '
  17        test_commit init main.txt init &&
  18        git branch conflicts &&
  19        test_commit on_master main.txt on_master &&
  20        git checkout conflicts &&
  21        test_commit on_conflicts main.txt on_conflicts
  22'
  23
  24
  25test_expect_success 'status when conflicts unresolved' '
  26        test_must_fail git merge master &&
  27        cat >expected <<-\EOF &&
  28        # On branch conflicts
  29        # You have unmerged paths.
  30        #   (fix conflicts and run "git commit")
  31        #
  32        # Unmerged paths:
  33        #   (use "git add/rm <file>..." as appropriate to mark resolution)
  34        #
  35        #       both modified:      main.txt
  36        #
  37        no changes added to commit (use "git add" and/or "git commit -a")
  38        EOF
  39        git status --untracked-files=no >actual &&
  40        test_i18ncmp expected actual
  41'
  42
  43
  44test_expect_success 'status when conflicts resolved before commit' '
  45        git reset --hard conflicts &&
  46        test_must_fail git merge master &&
  47        echo one >main.txt &&
  48        git add main.txt &&
  49        cat >expected <<-\EOF &&
  50        # On branch conflicts
  51        # All conflicts fixed but you are still merging.
  52        #   (use "git commit" to conclude merge)
  53        #
  54        # Changes to be committed:
  55        #
  56        #       modified:   main.txt
  57        #
  58        # Untracked files not listed (use -u option to show untracked files)
  59        EOF
  60        git status --untracked-files=no >actual &&
  61        test_i18ncmp expected actual
  62'
  63
  64
  65test_expect_success 'prepare for rebase conflicts' '
  66        git reset --hard master &&
  67        git checkout -b rebase_conflicts &&
  68        test_commit one_rebase main.txt one &&
  69        test_commit two_rebase main.txt two &&
  70        test_commit three_rebase main.txt three
  71'
  72
  73
  74test_expect_success 'status when rebase in progress before resolving conflicts' '
  75        test_when_finished "git rebase --abort" &&
  76        test_must_fail git rebase HEAD^ --onto HEAD^^ &&
  77        cat >expected <<-\EOF &&
  78        # Not currently on any branch.
  79        # You are currently rebasing.
  80        #   (fix conflicts and then run "git rebase --continue")
  81        #   (use "git rebase --skip" to skip this patch)
  82        #   (use "git rebase --abort" to check out the original branch)
  83        #
  84        # Unmerged paths:
  85        #   (use "git reset HEAD <file>..." to unstage)
  86        #   (use "git add/rm <file>..." as appropriate to mark resolution)
  87        #
  88        #       both modified:      main.txt
  89        #
  90        no changes added to commit (use "git add" and/or "git commit -a")
  91        EOF
  92        git status --untracked-files=no >actual &&
  93        test_i18ncmp expected actual
  94'
  95
  96
  97test_expect_success 'status when rebase in progress before rebase --continue' '
  98        git reset --hard rebase_conflicts &&
  99        test_when_finished "git rebase --abort" &&
 100        test_must_fail git rebase HEAD^ --onto HEAD^^ &&
 101        echo three >main.txt &&
 102        git add main.txt &&
 103        cat >expected <<-\EOF &&
 104        # Not currently on any branch.
 105        # You are currently rebasing.
 106        #   (all conflicts fixed: run "git rebase --continue")
 107        #
 108        # Changes to be committed:
 109        #   (use "git reset HEAD <file>..." to unstage)
 110        #
 111        #       modified:   main.txt
 112        #
 113        # Untracked files not listed (use -u option to show untracked files)
 114        EOF
 115        git status --untracked-files=no >actual &&
 116        test_i18ncmp expected actual
 117'
 118
 119
 120test_expect_success 'prepare for rebase_i_conflicts' '
 121        git reset --hard master &&
 122        git checkout -b rebase_i_conflicts &&
 123        test_commit one_unmerge main.txt one_unmerge &&
 124        git branch rebase_i_conflicts_second &&
 125        test_commit one_master main.txt one_master &&
 126        git checkout rebase_i_conflicts_second &&
 127        test_commit one_second main.txt one_second
 128'
 129
 130
 131test_expect_success 'status during rebase -i when conflicts unresolved' '
 132        test_when_finished "git rebase --abort" &&
 133        test_must_fail git rebase -i rebase_i_conflicts &&
 134        cat >expected <<-\EOF &&
 135        # Not currently on any branch.
 136        # You are currently rebasing.
 137        #   (fix conflicts and then run "git rebase --continue")
 138        #   (use "git rebase --skip" to skip this patch)
 139        #   (use "git rebase --abort" to check out the original branch)
 140        #
 141        # Unmerged paths:
 142        #   (use "git reset HEAD <file>..." to unstage)
 143        #   (use "git add/rm <file>..." as appropriate to mark resolution)
 144        #
 145        #       both modified:      main.txt
 146        #
 147        no changes added to commit (use "git add" and/or "git commit -a")
 148        EOF
 149        git status --untracked-files=no >actual &&
 150        test_i18ncmp expected actual
 151'
 152
 153
 154test_expect_success 'status during rebase -i after resolving conflicts' '
 155        git reset --hard rebase_i_conflicts_second &&
 156        test_when_finished "git rebase --abort" &&
 157        test_must_fail git rebase -i rebase_i_conflicts &&
 158        git add main.txt &&
 159        cat >expected <<-\EOF &&
 160        # Not currently on any branch.
 161        # You are currently rebasing.
 162        #   (all conflicts fixed: run "git rebase --continue")
 163        #
 164        # Changes to be committed:
 165        #   (use "git reset HEAD <file>..." to unstage)
 166        #
 167        #       modified:   main.txt
 168        #
 169        # Untracked files not listed (use -u option to show untracked files)
 170        EOF
 171        git status --untracked-files=no >actual &&
 172        test_i18ncmp expected actual
 173'
 174
 175
 176test_expect_success 'status when rebasing -i in edit mode' '
 177        git reset --hard master &&
 178        git checkout -b rebase_i_edit &&
 179        test_commit one_rebase_i main.txt one &&
 180        test_commit two_rebase_i main.txt two &&
 181        test_commit three_rebase_i main.txt three &&
 182        FAKE_LINES="1 edit 2" &&
 183        export FAKE_LINES &&
 184        test_when_finished "git rebase --abort" &&
 185        git rebase -i HEAD~2 &&
 186        cat >expected <<-\EOF &&
 187        # Not currently on any branch.
 188        # You are currently editing a commit during a rebase.
 189        #   (use "git commit --amend" to amend the current commit)
 190        #   (use "git rebase --continue" once you are satisfied with your changes)
 191        #
 192        nothing to commit (use -u to show untracked files)
 193        EOF
 194        git status --untracked-files=no >actual &&
 195        test_i18ncmp expected actual
 196'
 197
 198
 199test_expect_success 'prepare am_session' '
 200        git reset --hard master &&
 201        git checkout -b am_session &&
 202        test_commit one_am one.txt "one" &&
 203        test_commit two_am two.txt "two" &&
 204        test_commit three_am three.txt "three"
 205'
 206
 207
 208test_expect_success 'status in an am session: file already exists' '
 209        git checkout -b am_already_exists &&
 210        test_when_finished "rm Maildir/* && git am --abort" &&
 211        git format-patch -1 -oMaildir &&
 212        test_must_fail git am Maildir/*.patch &&
 213        cat >expected <<-\EOF &&
 214        # On branch am_already_exists
 215        # You are in the middle of an am session.
 216        #   (fix conflicts and then run "git am --resolved")
 217        #   (use "git am --skip" to skip this patch)
 218        #   (use "git am --abort" to restore the original branch)
 219        #
 220        nothing to commit (use -u to show untracked files)
 221        EOF
 222        git status --untracked-files=no >actual &&
 223        test_i18ncmp expected actual
 224'
 225
 226
 227test_expect_success 'status in an am session: file does not exist' '
 228        git reset --hard am_session &&
 229        git checkout -b am_not_exists &&
 230        git rm three.txt &&
 231        git commit -m "delete three.txt" &&
 232        test_when_finished "rm Maildir/* && git am --abort" &&
 233        git format-patch -1 -oMaildir &&
 234        test_must_fail git am Maildir/*.patch &&
 235        cat >expected <<-\EOF &&
 236        # On branch am_not_exists
 237        # You are in the middle of an am session.
 238        #   (fix conflicts and then run "git am --resolved")
 239        #   (use "git am --skip" to skip this patch)
 240        #   (use "git am --abort" to restore the original branch)
 241        #
 242        nothing to commit (use -u to show untracked files)
 243        EOF
 244        git status --untracked-files=no >actual &&
 245        test_i18ncmp expected actual
 246'
 247
 248
 249test_expect_success 'status in an am session: empty patch' '
 250        git reset --hard am_session &&
 251        git checkout -b am_empty &&
 252        test_when_finished "rm Maildir/* && git am --abort" &&
 253        git format-patch -3 -oMaildir &&
 254        git rm one.txt two.txt three.txt &&
 255        git commit -m "delete all am_empty" &&
 256        echo error >Maildir/0002-two_am.patch &&
 257        test_must_fail git am Maildir/*.patch &&
 258        cat >expected <<-\EOF &&
 259        # On branch am_empty
 260        # You are in the middle of an am session.
 261        # The current patch is empty.
 262        #   (use "git am --skip" to skip this patch)
 263        #   (use "git am --abort" to restore the original branch)
 264        #
 265        nothing to commit (use -u to show untracked files)
 266        EOF
 267        git status --untracked-files=no >actual &&
 268        test_i18ncmp expected actual
 269'
 270
 271
 272test_expect_success 'status when bisecting' '
 273        git reset --hard master &&
 274        git checkout -b bisect &&
 275        test_commit one_bisect main.txt one &&
 276        test_commit two_bisect main.txt two &&
 277        test_commit three_bisect main.txt three &&
 278        test_when_finished "git bisect reset" &&
 279        git bisect start &&
 280        git bisect bad &&
 281        git bisect good one_bisect &&
 282        cat >expected <<-\EOF &&
 283        # Not currently on any branch.
 284        # You are currently bisecting.
 285        #   (use "git bisect reset" to get back to the original branch)
 286        #
 287        nothing to commit (use -u to show untracked files)
 288        EOF
 289        git status --untracked-files=no >actual &&
 290        test_i18ncmp expected actual
 291'
 292
 293
 294test_expect_success 'status when rebase conflicts with statushints disabled' '
 295        git reset --hard master &&
 296        git checkout -b statushints_disabled &&
 297        test_when_finished "git config --local advice.statushints true" &&
 298        git config --local advice.statushints false &&
 299        test_commit one_statushints main.txt one &&
 300        test_commit two_statushints main.txt two &&
 301        test_commit three_statushints main.txt three &&
 302        test_when_finished "git rebase --abort" &&
 303        test_must_fail git rebase HEAD^ --onto HEAD^^ &&
 304        cat >expected <<-\EOF &&
 305        # Not currently on any branch.
 306        # You are currently rebasing.
 307        #
 308        # Unmerged paths:
 309        #       both modified:      main.txt
 310        #
 311        no changes added to commit
 312        EOF
 313        git status --untracked-files=no >actual &&
 314        test_i18ncmp expected actual
 315'
 316
 317
 318test_expect_success 'prepare for cherry-pick conflicts' '
 319        git reset --hard master &&
 320        git checkout -b cherry_branch &&
 321        test_commit one_cherry main.txt one &&
 322        test_commit two_cherries main.txt two &&
 323        git checkout -b cherry_branch_second &&
 324        test_commit second_cherry main.txt second &&
 325        git checkout cherry_branch &&
 326        test_commit three_cherries main.txt three
 327'
 328
 329
 330test_expect_success 'status when cherry-picking before resolving conflicts' '
 331        test_when_finished "git cherry-pick --abort" &&
 332        test_must_fail git cherry-pick cherry_branch_second &&
 333        cat >expected <<-\EOF &&
 334        # On branch cherry_branch
 335        # You are currently cherry-picking.
 336        #   (fix conflicts and run "git commit")
 337        #
 338        # Unmerged paths:
 339        #   (use "git add/rm <file>..." as appropriate to mark resolution)
 340        #
 341        #       both modified:      main.txt
 342        #
 343        no changes added to commit (use "git add" and/or "git commit -a")
 344        EOF
 345        git status --untracked-files=no >actual &&
 346        test_i18ncmp expected actual
 347'
 348
 349
 350test_expect_success 'status when cherry-picking after resolving conflicts' '
 351        git reset --hard cherry_branch &&
 352        test_when_finished "git cherry-pick --abort" &&
 353        test_must_fail git cherry-pick cherry_branch_second &&
 354        echo end >main.txt &&
 355        git add main.txt &&
 356        cat >expected <<-\EOF &&
 357        # On branch cherry_branch
 358        # You are currently cherry-picking.
 359        #   (all conflicts fixed: run "git commit")
 360        #
 361        # Changes to be committed:
 362        #
 363        #       modified:   main.txt
 364        #
 365        # Untracked files not listed (use -u option to show untracked files)
 366        EOF
 367        git status --untracked-files=no >actual &&
 368        test_i18ncmp expected actual
 369'
 370
 371
 372test_done