git
[Ported from github.com/git/git] Sync with Git 2.56.1
Brought by drakestapleton
git / t / t3418-rebase-continue.sh
| 1 | #!/bin/sh |
| 2 | |
| 3 | test_description='git rebase --continue tests' |
| 4 | |
| 5 | GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main |
| 6 | export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME |
| 7 | |
| 8 | . ./test-lib.sh |
| 9 | |
| 10 | . "$TEST_DIRECTORY"/lib-rebase.sh |
| 11 | |
| 12 | set_fake_editor |
| 13 | |
| 14 | test_expect_success 'setup' ' |
| 15 | test_commit "commit-new-file-F1" F1 1 && |
| 16 | test_commit "commit-new-file-F2" F2 2 && |
| 17 | |
| 18 | git checkout -b topic HEAD^ && |
| 19 | test_commit "commit-new-file-F2-on-topic-branch" F2 22 && |
| 20 | |
| 21 | git checkout main |
| 22 | ' |
| 23 | |
| 24 | test_expect_success 'merge based rebase --continue with works with touched file' ' |
| 25 | rm -fr .git/rebase-* && |
| 26 | git reset --hard && |
| 27 | git checkout main && |
| 28 | |
| 29 | FAKE_LINES="edit 1" git rebase -i HEAD^ && |
| 30 | test-tool chmtime =-60 F1 && |
| 31 | test_cmp_rev commit-new-file-F2 REBASE_HEAD && |
| 32 | git rebase --continue && |
| 33 | test_ref_missing REBASE_HEAD |
| 34 | ' |
| 35 | |
| 36 | test_expect_success 'merge based rebase --continue removes .git/MERGE_MSG' ' |
| 37 | git checkout -f --detach topic && |
| 38 | |
| 39 | test_must_fail git rebase --onto main HEAD^ && |
| 40 | git read-tree --reset -u HEAD && |
| 41 | test_path_is_file .git/MERGE_MSG && |
| 42 | git show-ref --verify AUTO_MERGE && |
| 43 | test_cmp_rev commit-new-file-F2-on-topic-branch REBASE_HEAD && |
| 44 | git rebase --continue && |
| 45 | test_path_is_missing .git/MERGE_MSG && |
| 46 | test_ref_missing AUTO_MERGE && |
| 47 | test_ref_missing REBASE_HEAD |
| 48 | ' |
| 49 | |
| 50 | test_expect_success 'apply based rebase --continue works with touched file' ' |
| 51 | rm -fr .git/rebase-* && |
| 52 | git reset --hard && |
| 53 | git checkout main && |
| 54 | |
| 55 | test_must_fail git rebase --apply --onto main main topic && |
| 56 | echo "Resolved" >F2 && |
| 57 | git add F2 && |
| 58 | test-tool chmtime =-60 F1 && |
| 59 | git rebase --continue |
| 60 | ' |
| 61 | |
| 62 | test_expect_success 'rebase --continue can not be used with other options' ' |
| 63 | test_must_fail git rebase -v --continue && |
| 64 | test_must_fail git rebase --continue -v |
| 65 | ' |
| 66 | |
| 67 | test_expect_success 'rebase --continue remembers merge strategy and options' ' |
| 68 | rm -fr .git/rebase-* && |
| 69 | git reset --hard commit-new-file-F2-on-topic-branch && |
| 70 | test_commit "commit-new-file-F3-on-topic-branch" F3 32 && |
| 71 | test_when_finished "rm -fr test-bin" && |
| 72 | mkdir test-bin && |
| 73 | |
| 74 | write_script test-bin/git-merge-funny <<-\EOF && |
| 75 | printf "[%s]\n" $# "$1" "$2" "$3" "$5" >actual |
| 76 | shift 3 && |
| 77 | exec git merge-recursive "$@" |
| 78 | EOF |
| 79 | |
| 80 | cat >expect <<-\EOF && |
| 81 | [7] |
| 82 | [--option=arg with space] |
| 83 | [--op"tion\] |
| 84 | [--new |
| 85 | line ] |
| 86 | [--] |
| 87 | EOF |
| 88 | |
| 89 | rm -f actual && |
| 90 | ( |
| 91 | PATH=./test-bin:$PATH && |
| 92 | test_must_fail git rebase -s funny -X"option=arg with space" \ |
| 93 | -Xop\"tion\\ -X"new${LF}line " main topic |
| 94 | ) && |
| 95 | test_cmp expect actual && |
| 96 | rm actual && |
| 97 | echo "Resolved" >F2 && |
| 98 | git add F2 && |
| 99 | ( |
| 100 | PATH=./test-bin:$PATH && |
| 101 | git rebase --continue |
| 102 | ) && |
| 103 | test_cmp expect actual |
| 104 | ' |
| 105 | |
| 106 | test_expect_success 'rebase -r passes merge strategy options correctly' ' |
| 107 | rm -fr .git/rebase-* && |
| 108 | git reset --hard commit-new-file-F3-on-topic-branch && |
| 109 | test_commit merge-theirs && |
| 110 | git reset --hard HEAD^ && |
| 111 | test_commit some-other-commit && |
| 112 | test_tick && |
| 113 | git merge --no-ff merge-theirs && |
| 114 | FAKE_LINES="1 3 edit 4 5 7 8 9" git rebase -i -f -r -m \ |
| 115 | -s recursive --strategy-option=theirs HEAD~2 && |
| 116 | test_commit force-change-ours && |
| 117 | git rebase --continue |
| 118 | ' |
| 119 | |
| 120 | test_expect_success '--skip after failed fixup cleans commit message' ' |
| 121 | test_when_finished "test_might_fail git rebase --abort" && |
| 122 | git checkout -b with-conflicting-fixup && |
| 123 | test_commit wants-fixup && |
| 124 | test_commit "fixup 1" wants-fixup.t 1 wants-fixup-1 && |
| 125 | test_commit "fixup 2" wants-fixup.t 2 wants-fixup-2 && |
| 126 | test_commit "fixup 3" wants-fixup.t 3 wants-fixup-3 && |
| 127 | test_must_fail env FAKE_LINES="1 fixup 2 squash 4" \ |
| 128 | git rebase -i HEAD~4 && |
| 129 | |
| 130 | : now there is a conflict, and comments in the commit message && |
| 131 | test_commit_message HEAD <<-\EOF && |
| 132 | # This is a combination of 2 commits. |
| 133 | # This is the 1st commit message: |
| 134 | |
| 135 | wants-fixup |
| 136 | |
| 137 | # The commit message #2 will be skipped: |
| 138 | |
| 139 | # fixup 1 |
| 140 | EOF |
| 141 | |
| 142 | : skip and continue && |
| 143 | test_config commit.status false && |
| 144 | echo "cp \"\$1\" .git/copy.txt" | write_script copy-editor.sh && |
| 145 | (test_set_editor "$PWD/copy-editor.sh" && git rebase --skip) && |
| 146 | |
| 147 | : the user should not have had to edit the commit message && |
| 148 | test_path_is_missing .git/copy.txt && |
| 149 | |
| 150 | : now the comments in the commit message should have been cleaned up && |
| 151 | test_commit_message HEAD -m wants-fixup && |
| 152 | |
| 153 | : now, let us ensure that "squash" is handled correctly && |
| 154 | git reset --hard wants-fixup-3 && |
| 155 | test_must_fail env \ |
| 156 | FAKE_LINES="1 squash 2 squash 1 squash 3 squash 1 squash 4 squash 1" \ |
| 157 | git rebase -i HEAD~4 && |
| 158 | |
| 159 | : the second squash failed, but there are two more in the chain && |
| 160 | (test_set_editor "$PWD/copy-editor.sh" && |
| 161 | test_must_fail git rebase --skip) && |
| 162 | |
| 163 | : not the final squash, no need to edit the commit message && |
| 164 | test_path_is_missing .git/copy.txt && |
| 165 | |
| 166 | : The first and third squashes succeeded, therefore: && |
| 167 | test_commit_message HEAD <<-\EOF && |
| 168 | # This is a combination of 3 commits. |
| 169 | # This is the 1st commit message: |
| 170 | |
| 171 | wants-fixup |
| 172 | |
| 173 | # This is the commit message #2: |
| 174 | |
| 175 | fixup 1 |
| 176 | |
| 177 | # This is the commit message #3: |
| 178 | |
| 179 | fixup 2 |
| 180 | EOF |
| 181 | |
| 182 | (test_set_editor "$PWD/copy-editor.sh" && |
| 183 | test_must_fail git rebase --skip) && |
| 184 | : not the final squash, no need to edit the commit message && |
| 185 | test_path_is_missing .git/copy.txt && |
| 186 | |
| 187 | : The first, third and fifth squashes succeeded, therefore: && |
| 188 | cat >expect <<-\EOF && |
| 189 | # This is a combination of 4 commits. |
| 190 | # This is the 1st commit message: |
| 191 | |
| 192 | wants-fixup |
| 193 | |
| 194 | # This is the commit message #2: |
| 195 | |
| 196 | fixup 1 |
| 197 | |
| 198 | # This is the commit message #3: |
| 199 | |
| 200 | fixup 2 |
| 201 | |
| 202 | # This is the commit message #4: |
| 203 | |
| 204 | fixup 3 |
| 205 | EOF |
| 206 | test_commit_message HEAD expect && |
| 207 | |
| 208 | (test_set_editor "$PWD/copy-editor.sh" && git rebase --skip) && |
| 209 | test_commit_message HEAD <<-\EOF && |
| 210 | wants-fixup |
| 211 | |
| 212 | fixup 1 |
| 213 | |
| 214 | fixup 2 |
| 215 | |
| 216 | fixup 3 |
| 217 | EOF |
| 218 | |
| 219 | : Final squash failed, but there was still a squash && |
| 220 | test_cmp expect .git/copy.txt |
| 221 | ' |
| 222 | |
| 223 | test_expect_success 'setup rerere database' ' |
| 224 | rm -fr .git/rebase-* && |
| 225 | git reset --hard commit-new-file-F3-on-topic-branch && |
| 226 | git checkout main && |
| 227 | test_commit "commit-new-file-F3" F3 3 && |
| 228 | test_config rerere.enabled true && |
| 229 | git update-ref refs/heads/topic commit-new-file-F3-on-topic-branch && |
| 230 | test_must_fail git rebase -m main topic && |
| 231 | echo "Resolved" >F2 && |
| 232 | cp F2 expected-F2 && |
| 233 | git add F2 && |
| 234 | test_must_fail git rebase --continue && |
| 235 | echo "Resolved" >F3 && |
| 236 | cp F3 expected-F3 && |
| 237 | git add F3 && |
| 238 | git rebase --continue && |
| 239 | git reset --hard topic@{1} |
| 240 | ' |
| 241 | |
| 242 | prepare () { |
| 243 | rm -fr .git/rebase-* && |
| 244 | git reset --hard commit-new-file-F3-on-topic-branch && |
| 245 | git checkout main && |
| 246 | test_config rerere.enabled true |
| 247 | } |
| 248 | |
| 249 | test_rerere_autoupdate () { |
| 250 | action=$1 && |
| 251 | test_expect_success "rebase $action --continue remembers --rerere-autoupdate" ' |
| 252 | prepare && |
| 253 | test_must_fail git rebase $action --rerere-autoupdate main topic && |
| 254 | test_cmp expected-F2 F2 && |
| 255 | git diff-files --quiet && |
| 256 | test_must_fail git rebase --continue && |
| 257 | test_cmp expected-F3 F3 && |
| 258 | git diff-files --quiet && |
| 259 | git rebase --continue |
| 260 | ' |
| 261 | |
| 262 | test_expect_success "rebase $action --continue honors rerere.autoUpdate" ' |
| 263 | prepare && |
| 264 | test_config rerere.autoupdate true && |
| 265 | test_must_fail git rebase $action main topic && |
| 266 | test_cmp expected-F2 F2 && |
| 267 | git diff-files --quiet && |
| 268 | test_must_fail git rebase --continue && |
| 269 | test_cmp expected-F3 F3 && |
| 270 | git diff-files --quiet && |
| 271 | git rebase --continue |
| 272 | ' |
| 273 | |
| 274 | test_expect_success "rebase $action --continue remembers --no-rerere-autoupdate" ' |
| 275 | prepare && |
| 276 | test_config rerere.autoupdate true && |
| 277 | test_must_fail git rebase $action --no-rerere-autoupdate main topic && |
| 278 | test_cmp expected-F2 F2 && |
| 279 | test_must_fail git diff-files --quiet && |
| 280 | git add F2 && |
| 281 | test_must_fail git rebase --continue && |
| 282 | test_cmp expected-F3 F3 && |
| 283 | test_must_fail git diff-files --quiet && |
| 284 | git add F3 && |
| 285 | git rebase --continue |
| 286 | ' |
| 287 | } |
| 288 | |
| 289 | test_rerere_autoupdate --apply |
| 290 | test_rerere_autoupdate -m |
| 291 | GIT_SEQUENCE_EDITOR=: && export GIT_SEQUENCE_EDITOR |
| 292 | test_rerere_autoupdate -i |
| 293 | unset GIT_SEQUENCE_EDITOR |
| 294 | |
| 295 | test_expect_success 'the todo command "break" works' ' |
| 296 | rm -f execed && |
| 297 | FAKE_LINES="break b exec_>execed" git rebase -i HEAD && |
| 298 | test_path_is_missing execed && |
| 299 | git rebase --continue && |
| 300 | test_path_is_missing execed && |
| 301 | git rebase --continue && |
| 302 | test_path_is_file execed |
| 303 | ' |
| 304 | |
| 305 | test_expect_success 'patch file is removed before break command' ' |
| 306 | test_when_finished "git rebase --abort" && |
| 307 | cat >todo <<-\EOF && |
| 308 | pick commit-new-file-F2-on-topic-branch |
| 309 | break |
| 310 | EOF |
| 311 | |
| 312 | ( |
| 313 | set_replace_editor todo && |
| 314 | test_must_fail git rebase -i --onto commit-new-file-F2 HEAD |
| 315 | ) && |
| 316 | test_path_is_file .git/rebase-merge/patch && |
| 317 | echo 22>F2 && |
| 318 | git add F2 && |
| 319 | git rebase --continue && |
| 320 | test_path_is_missing .git/rebase-merge/patch |
| 321 | ' |
| 322 | |
| 323 | test_expect_success '--reschedule-failed-exec' ' |
| 324 | test_when_finished "git rebase --abort" && |
| 325 | test_must_fail git rebase -x false --reschedule-failed-exec HEAD^ && |
| 326 | test_grep "^exec false" .git/rebase-merge/git-rebase-todo && |
| 327 | git rebase --abort && |
| 328 | test_must_fail git -c rebase.rescheduleFailedExec=true \ |
| 329 | rebase -x false HEAD^ 2>err && |
| 330 | test_grep "^exec false" .git/rebase-merge/git-rebase-todo && |
| 331 | test_grep "has been rescheduled" err |
| 332 | ' |
| 333 | |
| 334 | test_expect_success 'rebase.rescheduleFailedExec only affects `rebase -i`' ' |
| 335 | test_config rebase.rescheduleFailedExec true && |
| 336 | test_must_fail git rebase -x false HEAD^ && |
| 337 | test_grep "^exec false" .git/rebase-merge/git-rebase-todo && |
| 338 | git rebase --abort && |
| 339 | git rebase HEAD^ |
| 340 | ' |
| 341 | |
| 342 | test_expect_success 'rebase.rescheduleFailedExec=true & --no-reschedule-failed-exec' ' |
| 343 | test_when_finished "git rebase --abort" && |
| 344 | test_config rebase.rescheduleFailedExec true && |
| 345 | test_must_fail git rebase -x false --no-reschedule-failed-exec HEAD~2 && |
| 346 | test_must_fail git rebase --continue 2>err && |
| 347 | test_grep ! "has been rescheduled" err |
| 348 | ' |
| 349 | |
| 350 | test_expect_success 'new rebase.rescheduleFailedExec=true setting in an ongoing rebase is ignored' ' |
| 351 | test_when_finished "git rebase --abort" && |
| 352 | test_must_fail git rebase -x false HEAD~2 && |
| 353 | test_config rebase.rescheduleFailedExec true && |
| 354 | test_must_fail git rebase --continue 2>err && |
| 355 | test_grep ! "has been rescheduled" err |
| 356 | ' |
| 357 | |
| 358 | test_expect_success 'there is no --no-reschedule-failed-exec in an ongoing rebase' ' |
| 359 | test_when_finished "git rebase --abort" && |
| 360 | test_must_fail git rebase -x false HEAD~2 && |
| 361 | test_expect_code 129 git rebase --continue --no-reschedule-failed-exec && |
| 362 | test_expect_code 129 git rebase --edit-todo --no-reschedule-failed-exec |
| 363 | ' |
| 364 | |
| 365 | test_expect_success !WITH_BREAKING_CHANGES 'no change in comment character due to conflicts markers with core.commentChar=auto' ' |
| 366 | git checkout -b branch-a && |
| 367 | test_commit A F1 && |
| 368 | git checkout -b branch-b HEAD^ && |
| 369 | test_commit B F1 && |
| 370 | test_must_fail git rebase branch-a && |
| 371 | printf "B\nA\n" >F1 && |
| 372 | git add F1 && |
| 373 | GIT_EDITOR="cat >actual" git -c core.commentChar=auto rebase --continue && |
| 374 | # Check that "#" is still the comment character. |
| 375 | test_grep "^# Changes to be committed" actual |
| 376 | ' |
| 377 | |
| 378 | test_orig_head_helper () { |
| 379 | test_when_finished 'git rebase --abort && |
| 380 | git checkout topic && |
| 381 | git reset --hard commit-new-file-F2-on-topic-branch' && |
| 382 | git update-ref -d ORIG_HEAD && |
| 383 | test_must_fail git rebase "$@" && |
| 384 | test_cmp_rev ORIG_HEAD commit-new-file-F2-on-topic-branch |
| 385 | } |
| 386 | |
| 387 | test_orig_head () { |
| 388 | type=$1 |
| 389 | test_expect_success "rebase $type sets ORIG_HEAD correctly" ' |
| 390 | git checkout topic && |
| 391 | git reset --hard commit-new-file-F2-on-topic-branch && |
| 392 | test_orig_head_helper $type main |
| 393 | ' |
| 394 | |
| 395 | test_expect_success "rebase $type <upstream> <branch> sets ORIG_HEAD correctly" ' |
| 396 | git checkout main && |
| 397 | test_orig_head_helper $type main topic |
| 398 | ' |
| 399 | } |
| 400 | |
| 401 | test_orig_head --apply |
| 402 | test_orig_head --merge |
| 403 | |
| 404 | test_expect_success 'rebase runs auto maintenance once it is done' ' |
| 405 | # topic and main both add F2, so the pick conflicts and the rebase |
| 406 | # stops before the exec runs. "--continue" commits the resolution |
| 407 | # first, then runs the exec, which fails and stops it again. |
| 408 | git checkout -b auto-maintenance topic && |
| 409 | test_must_fail env GIT_TRACE2_EVENT="$(pwd)/stop.txt" \ |
| 410 | git rebase -x "git commit --allow-empty -m exec && false" main && |
| 411 | test_subcommand_flex ! git maintenance run --auto <stop.txt && |
| 412 | echo resolved >F2 && |
| 413 | git add F2 && |
| 414 | test_must_fail env GIT_TRACE2_EVENT="$(pwd)/mid.txt" \ |
| 415 | git rebase --continue && |
| 416 | test_subcommand_flex git commit <mid.txt && |
| 417 | test_subcommand_flex ! git maintenance run --auto <mid.txt && |
| 418 | GIT_TRACE2_EVENT="$(pwd)/end.txt" git rebase --continue && |
| 419 | test_subcommand_flex git maintenance run --auto <end.txt && |
| 420 | grep "\"child_start\".*\"maintenance\"" end.txt >maintenance && |
| 421 | test_line_count = 1 maintenance |
| 422 | ' |
| 423 | |
| 424 | test_done |