69cb079dd16a636166c459284740a9c42b7592ad
   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-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-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 passes merge strategy options correctly' '
  78        rm -fr .git/rebase-* &&
  79        git reset --hard commit-new-file-F3-on-topic-branch &&
  80        test_commit theirs-to-merge &&
  81        git reset --hard HEAD^ &&
  82        test_commit some-commit &&
  83        test_tick &&
  84        git merge --no-ff theirs-to-merge &&
  85        FAKE_LINES="1 edit 2 3" git rebase -i -f -p -m \
  86                -s recursive --strategy-option=theirs HEAD~2 &&
  87        test_commit force-change &&
  88        git rebase --continue
  89'
  90
  91test_expect_failure '--skip after failed fixup cleans commit message' '
  92        test_when_finished "test_might_fail git rebase --abort" &&
  93        git checkout -b with-conflicting-fixup &&
  94        test_commit wants-fixup &&
  95        test_commit "fixup! wants-fixup" wants-fixup.t 1 wants-fixup-1 &&
  96        test_commit "fixup! wants-fixup" wants-fixup.t 2 wants-fixup-2 &&
  97        test_commit "fixup! wants-fixup" wants-fixup.t 3 wants-fixup-3 &&
  98        test_must_fail env FAKE_LINES="1 fixup 2 fixup 4" \
  99                git rebase -i HEAD~4 &&
 100
 101        : now there is a conflict, and comments in the commit message &&
 102        git show HEAD >out &&
 103        grep "fixup! wants-fixup" out &&
 104
 105        : skip and continue &&
 106        git rebase --skip &&
 107
 108        : now the comments in the commit message should have been cleaned up &&
 109        git show HEAD >out &&
 110        ! grep "fixup! wants-fixup" out
 111'
 112
 113test_expect_success 'setup rerere database' '
 114        rm -fr .git/rebase-* &&
 115        git reset --hard commit-new-file-F3-on-topic-branch &&
 116        git checkout master &&
 117        test_commit "commit-new-file-F3" F3 3 &&
 118        test_config rerere.enabled true &&
 119        test_must_fail git rebase -m master topic &&
 120        echo "Resolved" >F2 &&
 121        cp F2 expected-F2 &&
 122        git add F2 &&
 123        test_must_fail git rebase --continue &&
 124        echo "Resolved" >F3 &&
 125        cp F3 expected-F3 &&
 126        git add F3 &&
 127        git rebase --continue &&
 128        git reset --hard topic@{1}
 129'
 130
 131prepare () {
 132        rm -fr .git/rebase-* &&
 133        git reset --hard commit-new-file-F3-on-topic-branch &&
 134        git checkout master &&
 135        test_config rerere.enabled true
 136}
 137
 138test_rerere_autoupdate () {
 139        action=$1 &&
 140        test_expect_success "rebase $action --continue remembers --rerere-autoupdate" '
 141                prepare &&
 142                test_must_fail git rebase $action --rerere-autoupdate master topic &&
 143                test_cmp expected-F2 F2 &&
 144                git diff-files --quiet &&
 145                test_must_fail git rebase --continue &&
 146                test_cmp expected-F3 F3 &&
 147                git diff-files --quiet &&
 148                git rebase --continue
 149        '
 150
 151        test_expect_success "rebase $action --continue honors rerere.autoUpdate" '
 152                prepare &&
 153                test_config rerere.autoupdate true &&
 154                test_must_fail git rebase $action master topic &&
 155                test_cmp expected-F2 F2 &&
 156                git diff-files --quiet &&
 157                test_must_fail git rebase --continue &&
 158                test_cmp expected-F3 F3 &&
 159                git diff-files --quiet &&
 160                git rebase --continue
 161        '
 162
 163        test_expect_success "rebase $action --continue remembers --no-rerere-autoupdate" '
 164                prepare &&
 165                test_config rerere.autoupdate true &&
 166                test_must_fail git rebase $action --no-rerere-autoupdate master topic &&
 167                test_cmp expected-F2 F2 &&
 168                test_must_fail git diff-files --quiet &&
 169                git add F2 &&
 170                test_must_fail git rebase --continue &&
 171                test_cmp expected-F3 F3 &&
 172                test_must_fail git diff-files --quiet &&
 173                git add F3 &&
 174                git rebase --continue
 175        '
 176}
 177
 178test_rerere_autoupdate
 179test_rerere_autoupdate -m
 180GIT_SEQUENCE_EDITOR=: && export GIT_SEQUENCE_EDITOR
 181test_rerere_autoupdate -i
 182test_rerere_autoupdate --preserve-merges
 183
 184test_done