t / t3418-rebase-continue.shon commit Merge branch 'mp/for-each-ref-missing-name-or-email' (a477abe)
   1#!/bin/sh
   2
   3test_description='git rebase --continue tests'
   4
   5. ./test-lib.sh
   6
   7. "$TEST_DIRECTORY"/lib-rebase.sh
   8
   9set_fake_editor
  10
  11test_expect_success 'setup' '
  12        test_commit "commit-new-file-F1" F1 1 &&
  13        test_commit "commit-new-file-F2" F2 2 &&
  14
  15        git checkout -b topic HEAD^ &&
  16        test_commit "commit-new-file-F2-on-topic-branch" F2 22 &&
  17
  18        git checkout master
  19'
  20
  21test_expect_success 'interactive rebase --continue works with touched file' '
  22        rm -fr .git/rebase-* &&
  23        git reset --hard &&
  24        git checkout master &&
  25
  26        FAKE_LINES="edit 1" git rebase -i HEAD^ &&
  27        test-tool chmtime =-60 F1 &&
  28        git rebase --continue
  29'
  30
  31test_expect_success 'non-interactive rebase --continue works with touched file' '
  32        rm -fr .git/rebase-* &&
  33        git reset --hard &&
  34        git checkout master &&
  35
  36        test_must_fail git rebase --onto master master topic &&
  37        echo "Resolved" >F2 &&
  38        git add F2 &&
  39        test-tool chmtime =-60 F1 &&
  40        git rebase --continue
  41'
  42
  43test_expect_success 'rebase --continue can not be used with other options' '
  44        test_must_fail git rebase -v --continue &&
  45        test_must_fail git rebase --continue -v
  46'
  47
  48test_expect_success 'rebase --continue remembers merge strategy and options' '
  49        rm -fr .git/rebase-* &&
  50        git reset --hard commit-new-file-F2-on-topic-branch &&
  51        test_commit "commit-new-file-F3-on-topic-branch" F3 32 &&
  52        test_when_finished "rm -fr test-bin funny.was.run" &&
  53        mkdir test-bin &&
  54        cat >test-bin/git-merge-funny <<-EOF &&
  55        #!$SHELL_PATH
  56        case "\$1" in --opt) ;; *) exit 2 ;; esac
  57        shift &&
  58        >funny.was.run &&
  59        exec git merge-recursive "\$@"
  60        EOF
  61        chmod +x test-bin/git-merge-funny &&
  62        (
  63                PATH=./test-bin:$PATH &&
  64                test_must_fail git rebase -s funny -Xopt master topic
  65        ) &&
  66        test -f funny.was.run &&
  67        rm funny.was.run &&
  68        echo "Resolved" >F2 &&
  69        git add F2 &&
  70        (
  71                PATH=./test-bin:$PATH &&
  72                git rebase --continue
  73        ) &&
  74        test -f funny.was.run
  75'
  76
  77test_expect_success 'rebase -i --continue handles merge strategy and options' '
  78        rm -fr .git/rebase-* &&
  79        git reset --hard commit-new-file-F2-on-topic-branch &&
  80        test_commit "commit-new-file-F3-on-topic-branch-for-dash-i" F3 32 &&
  81        test_when_finished "rm -fr test-bin funny.was.run funny.args" &&
  82        mkdir test-bin &&
  83        cat >test-bin/git-merge-funny <<-EOF &&
  84        #!$SHELL_PATH
  85        echo "\$@" >>funny.args
  86        case "\$1" in --opt) ;; *) exit 2 ;; esac
  87        case "\$2" in --foo) ;; *) exit 2 ;; esac
  88        case "\$4" in --) ;; *) exit 2 ;; esac
  89        shift 2 &&
  90        >funny.was.run &&
  91        exec git merge-recursive "\$@"
  92        EOF
  93        chmod +x test-bin/git-merge-funny &&
  94        (
  95                PATH=./test-bin:$PATH &&
  96                test_must_fail git rebase -i -s funny -Xopt -Xfoo master topic
  97        ) &&
  98        test -f funny.was.run &&
  99        rm funny.was.run &&
 100        echo "Resolved" >F2 &&
 101        git add F2 &&
 102        (
 103                PATH=./test-bin:$PATH &&
 104                git rebase --continue
 105        ) &&
 106        test -f funny.was.run
 107'
 108
 109test_expect_success REBASE_P 'rebase passes merge strategy options correctly' '
 110        rm -fr .git/rebase-* &&
 111        git reset --hard commit-new-file-F3-on-topic-branch &&
 112        test_commit theirs-to-merge &&
 113        git reset --hard HEAD^ &&
 114        test_commit some-commit &&
 115        test_tick &&
 116        git merge --no-ff theirs-to-merge &&
 117        FAKE_LINES="1 edit 2 3" git rebase -i -f -p -m \
 118                -s recursive --strategy-option=theirs HEAD~2 &&
 119        test_commit force-change &&
 120        git rebase --continue
 121'
 122
 123test_expect_success '--skip after failed fixup cleans commit message' '
 124        test_when_finished "test_might_fail git rebase --abort" &&
 125        git checkout -b with-conflicting-fixup &&
 126        test_commit wants-fixup &&
 127        test_commit "fixup! wants-fixup" wants-fixup.t 1 wants-fixup-1 &&
 128        test_commit "fixup! wants-fixup" wants-fixup.t 2 wants-fixup-2 &&
 129        test_commit "fixup! wants-fixup" wants-fixup.t 3 wants-fixup-3 &&
 130        test_must_fail env FAKE_LINES="1 fixup 2 squash 4" \
 131                git rebase -i HEAD~4 &&
 132
 133        : now there is a conflict, and comments in the commit message &&
 134        git show HEAD >out &&
 135        grep "fixup! wants-fixup" out &&
 136
 137        : skip and continue &&
 138        echo "cp \"\$1\" .git/copy.txt" | write_script copy-editor.sh &&
 139        (test_set_editor "$PWD/copy-editor.sh" && git rebase --skip) &&
 140
 141        : the user should not have had to edit the commit message &&
 142        test_path_is_missing .git/copy.txt &&
 143
 144        : now the comments in the commit message should have been cleaned up &&
 145        git show HEAD >out &&
 146        ! grep "fixup! wants-fixup" out &&
 147
 148        : now, let us ensure that "squash" is handled correctly &&
 149        git reset --hard wants-fixup-3 &&
 150        test_must_fail env FAKE_LINES="1 squash 4 squash 2 squash 4" \
 151                git rebase -i HEAD~4 &&
 152
 153        : the first squash failed, but there are two more in the chain &&
 154        (test_set_editor "$PWD/copy-editor.sh" &&
 155         test_must_fail git rebase --skip) &&
 156
 157        : not the final squash, no need to edit the commit message &&
 158        test_path_is_missing .git/copy.txt &&
 159
 160        : The first squash was skipped, therefore: &&
 161        git show HEAD >out &&
 162        test_i18ngrep "# This is a combination of 2 commits" out &&
 163        test_i18ngrep "# This is the commit message #2:" out &&
 164
 165        (test_set_editor "$PWD/copy-editor.sh" && git rebase --skip) &&
 166        git show HEAD >out &&
 167        test_i18ngrep ! "# This is a combination" out &&
 168
 169        : Final squash failed, but there was still a squash &&
 170        test_i18ngrep "# This is a combination of 2 commits" .git/copy.txt &&
 171        test_i18ngrep "# This is the commit message #2:" .git/copy.txt
 172'
 173
 174test_expect_success 'setup rerere database' '
 175        rm -fr .git/rebase-* &&
 176        git reset --hard commit-new-file-F3-on-topic-branch &&
 177        git checkout master &&
 178        test_commit "commit-new-file-F3" F3 3 &&
 179        test_config rerere.enabled true &&
 180        git update-ref refs/heads/topic commit-new-file-F3-on-topic-branch &&
 181        test_must_fail git rebase -m master topic &&
 182        echo "Resolved" >F2 &&
 183        cp F2 expected-F2 &&
 184        git add F2 &&
 185        test_must_fail git rebase --continue &&
 186        echo "Resolved" >F3 &&
 187        cp F3 expected-F3 &&
 188        git add F3 &&
 189        git rebase --continue &&
 190        git reset --hard topic@{1}
 191'
 192
 193prepare () {
 194        rm -fr .git/rebase-* &&
 195        git reset --hard commit-new-file-F3-on-topic-branch &&
 196        git checkout master &&
 197        test_config rerere.enabled true
 198}
 199
 200test_rerere_autoupdate () {
 201        action=$1 &&
 202        test_expect_success "rebase $action --continue remembers --rerere-autoupdate" '
 203                prepare &&
 204                test_must_fail git rebase $action --rerere-autoupdate master topic &&
 205                test_cmp expected-F2 F2 &&
 206                git diff-files --quiet &&
 207                test_must_fail git rebase --continue &&
 208                test_cmp expected-F3 F3 &&
 209                git diff-files --quiet &&
 210                git rebase --continue
 211        '
 212
 213        test_expect_success "rebase $action --continue honors rerere.autoUpdate" '
 214                prepare &&
 215                test_config rerere.autoupdate true &&
 216                test_must_fail git rebase $action master topic &&
 217                test_cmp expected-F2 F2 &&
 218                git diff-files --quiet &&
 219                test_must_fail git rebase --continue &&
 220                test_cmp expected-F3 F3 &&
 221                git diff-files --quiet &&
 222                git rebase --continue
 223        '
 224
 225        test_expect_success "rebase $action --continue remembers --no-rerere-autoupdate" '
 226                prepare &&
 227                test_config rerere.autoupdate true &&
 228                test_must_fail git rebase $action --no-rerere-autoupdate master topic &&
 229                test_cmp expected-F2 F2 &&
 230                test_must_fail git diff-files --quiet &&
 231                git add F2 &&
 232                test_must_fail git rebase --continue &&
 233                test_cmp expected-F3 F3 &&
 234                test_must_fail git diff-files --quiet &&
 235                git add F3 &&
 236                git rebase --continue
 237        '
 238}
 239
 240test_rerere_autoupdate
 241test_rerere_autoupdate -m
 242GIT_SEQUENCE_EDITOR=: && export GIT_SEQUENCE_EDITOR
 243test_rerere_autoupdate -i
 244test_have_prereq !REBASE_P || test_rerere_autoupdate --preserve-merges
 245unset GIT_SEQUENCE_EDITOR
 246
 247test_expect_success 'the todo command "break" works' '
 248        rm -f execed &&
 249        FAKE_LINES="break b exec_>execed" git rebase -i HEAD &&
 250        test_path_is_missing execed &&
 251        git rebase --continue &&
 252        test_path_is_missing execed &&
 253        git rebase --continue &&
 254        test_path_is_file execed
 255'
 256
 257test_expect_success '--reschedule-failed-exec' '
 258        test_when_finished "git rebase --abort" &&
 259        test_must_fail git rebase -x false --reschedule-failed-exec HEAD^ &&
 260        grep "^exec false" .git/rebase-merge/git-rebase-todo &&
 261        git rebase --abort &&
 262        test_must_fail git -c rebase.rescheduleFailedExec=true \
 263                rebase -x false HEAD^ 2>err &&
 264        grep "^exec false" .git/rebase-merge/git-rebase-todo &&
 265        test_i18ngrep "has been rescheduled" err
 266'
 267
 268test_expect_success 'rebase.reschedulefailedexec only affects `rebase -i`' '
 269        test_config rebase.reschedulefailedexec true &&
 270        test_must_fail git rebase -x false HEAD^ &&
 271        grep "^exec false" .git/rebase-merge/git-rebase-todo &&
 272        git rebase --abort &&
 273        git rebase HEAD^
 274'
 275
 276test_done