Merge branch 'pw/rebase-i-keep-reword-after-conflict'
Bugfix for "rebase -i" corner case regression. * pw/rebase-i-keep-reword-after-conflict: sequencer: do not squash 'reword' commits when we hit conflictsmaint
commit
d349e188ab
23
sequencer.c
23
sequencer.c
|
@ -3219,10 +3219,27 @@ static int pick_commits(struct todo_list *todo_list, struct replay_opts *opts)
|
||||||
intend_to_amend();
|
intend_to_amend();
|
||||||
return error_failed_squash(item->commit, opts,
|
return error_failed_squash(item->commit, opts,
|
||||||
item->arg_len, item->arg);
|
item->arg_len, item->arg);
|
||||||
} else if (res && is_rebase_i(opts) && item->commit)
|
} else if (res && is_rebase_i(opts) && item->commit) {
|
||||||
|
int to_amend = 0;
|
||||||
|
struct object_id oid;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* If we are rewording and have either
|
||||||
|
* fast-forwarded already, or are about to
|
||||||
|
* create a new root commit, we want to amend,
|
||||||
|
* otherwise we do not.
|
||||||
|
*/
|
||||||
|
if (item->command == TODO_REWORD &&
|
||||||
|
!get_oid("HEAD", &oid) &&
|
||||||
|
(!oidcmp(&item->commit->object.oid, &oid) ||
|
||||||
|
(opts->have_squash_onto &&
|
||||||
|
!oidcmp(&opts->squash_onto, &oid))))
|
||||||
|
to_amend = 1;
|
||||||
|
|
||||||
return res | error_with_patch(item->commit,
|
return res | error_with_patch(item->commit,
|
||||||
item->arg, item->arg_len, opts, res,
|
item->arg, item->arg_len, opts,
|
||||||
item->command == TODO_REWORD);
|
res, to_amend);
|
||||||
|
}
|
||||||
} else if (item->command == TODO_EXEC) {
|
} else if (item->command == TODO_EXEC) {
|
||||||
char *end_of_arg = (char *)(item->arg + item->arg_len);
|
char *end_of_arg = (char *)(item->arg + item->arg_len);
|
||||||
int saved = *end_of_arg;
|
int saved = *end_of_arg;
|
||||||
|
|
|
@ -981,7 +981,35 @@ test_expect_success 'rebase -i --root reword root commit' '
|
||||||
test -z "$(git show -s --format=%p HEAD^)"
|
test -z "$(git show -s --format=%p HEAD^)"
|
||||||
'
|
'
|
||||||
|
|
||||||
|
test_expect_success 'rebase -i --root when root has untracked file confilct' '
|
||||||
|
test_when_finished "reset_rebase" &&
|
||||||
|
git checkout -b failing-root-pick A &&
|
||||||
|
echo x >file2 &&
|
||||||
|
git rm file1 &&
|
||||||
|
git commit -m "remove file 1 add file 2" &&
|
||||||
|
echo z >file1 &&
|
||||||
|
set_fake_editor &&
|
||||||
|
test_must_fail env FAKE_LINES="1 2" git rebase -i --root &&
|
||||||
|
rm file1 &&
|
||||||
|
git rebase --continue &&
|
||||||
|
test "$(git log -1 --format=%B)" = "remove file 1 add file 2" &&
|
||||||
|
test "$(git rev-list --count HEAD)" = 2
|
||||||
|
'
|
||||||
|
|
||||||
|
test_expect_success 'rebase -i --root reword root when root has untracked file conflict' '
|
||||||
|
test_when_finished "reset_rebase" &&
|
||||||
|
echo z>file1 &&
|
||||||
|
set_fake_editor &&
|
||||||
|
test_must_fail env FAKE_LINES="reword 1 2" \
|
||||||
|
FAKE_COMMIT_MESSAGE="Modified A" git rebase -i --root &&
|
||||||
|
rm file1 &&
|
||||||
|
FAKE_COMMIT_MESSAGE="Reworded A" git rebase --continue &&
|
||||||
|
test "$(git log -1 --format=%B HEAD^)" = "Reworded A" &&
|
||||||
|
test "$(git rev-list --count HEAD)" = 2
|
||||||
|
'
|
||||||
|
|
||||||
test_expect_success C_LOCALE_OUTPUT 'rebase --edit-todo does not work on non-interactive rebase' '
|
test_expect_success C_LOCALE_OUTPUT 'rebase --edit-todo does not work on non-interactive rebase' '
|
||||||
|
git checkout reword-root-branch &&
|
||||||
git reset --hard &&
|
git reset --hard &&
|
||||||
git checkout conflict-branch &&
|
git checkout conflict-branch &&
|
||||||
set_fake_editor &&
|
set_fake_editor &&
|
||||||
|
|
|
@ -0,0 +1,48 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
test_description='git rebase interactive with rewording'
|
||||||
|
|
||||||
|
. ./test-lib.sh
|
||||||
|
|
||||||
|
. "$TEST_DIRECTORY"/lib-rebase.sh
|
||||||
|
|
||||||
|
test_expect_success 'setup' '
|
||||||
|
test_commit master file-1 test &&
|
||||||
|
|
||||||
|
git checkout -b stuff &&
|
||||||
|
|
||||||
|
test_commit feature_a file-2 aaa &&
|
||||||
|
test_commit feature_b file-2 ddd
|
||||||
|
'
|
||||||
|
|
||||||
|
test_expect_success 'reword without issues functions as intended' '
|
||||||
|
test_when_finished "reset_rebase" &&
|
||||||
|
|
||||||
|
git checkout stuff^0 &&
|
||||||
|
|
||||||
|
set_fake_editor &&
|
||||||
|
FAKE_LINES="pick 1 reword 2" FAKE_COMMIT_MESSAGE="feature_b_reworded" \
|
||||||
|
git rebase -i -v master &&
|
||||||
|
|
||||||
|
test "$(git log -1 --format=%B)" = "feature_b_reworded" &&
|
||||||
|
test $(git rev-list --count HEAD) = 3
|
||||||
|
'
|
||||||
|
|
||||||
|
test_expect_success 'reword after a conflict preserves commit' '
|
||||||
|
test_when_finished "reset_rebase" &&
|
||||||
|
|
||||||
|
git checkout stuff^0 &&
|
||||||
|
|
||||||
|
set_fake_editor &&
|
||||||
|
test_must_fail env FAKE_LINES="reword 2" \
|
||||||
|
git rebase -i -v master &&
|
||||||
|
|
||||||
|
git checkout --theirs file-2 &&
|
||||||
|
git add file-2 &&
|
||||||
|
FAKE_COMMIT_MESSAGE="feature_b_reworded" git rebase --continue &&
|
||||||
|
|
||||||
|
test "$(git log -1 --format=%B)" = "feature_b_reworded" &&
|
||||||
|
test $(git rev-list --count HEAD) = 2
|
||||||
|
'
|
||||||
|
|
||||||
|
test_done
|
Loading…
Reference in New Issue