rebase -i: redo tasks that die during cherry-pick

When rebase--interactive processes a task, it removes the item from the todo list and appends it to another list of executed tasks. If a pick (this includes squash and fixup) fails before the index has recorded the changes, take the corresponding item and put it on the todo list again. Otherwise, the changes introduced by the scheduled commit would be lost. That kind of decision is possible since the cherry-pick command signals why it failed to apply the changes of the given commit. Either the changes are recorded in the index using a conflict (return value 1) and rebase does not continue until they are resolved or the changes are not recorded in the index (return value neither 0 nor 1) and rebase has to try again with the same task. Add a test cases for regression testing to the "rebase-interactive" test suite. Signed-off-by: Fabian Ruch <bafain@gmail.com> Signed-off-by: Phil Hord <hordp@cisco.com> Acked-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Phil Hord committed Apr 28, 2015 at 18:55 UTC 8cbc57ca1109ba455c6098654b7d732a01fd89fd
2 files changed +63
git-rebase--interactive.sh
+16
@@ -132,6 +132,16 @@ mark_action_done () {
132 fi
133 }
134
135 +# Put the last action marked done at the beginning of the todo list
136 +# again. If there has not been an action marked done yet, leave the list of
137 +# items on the todo list unchanged.
138 +reschedule_last_action () {
139 + tail -n 1 "$done" | cat - "$todo" >"$todo".new
140 + sed -e \$d <"$done" >"$done".new
141 + mv -f "$todo".new "$todo"
142 + mv -f "$done".new "$done"
143 +}
144 +
145 append_todo_help () {
146 git stripspace --comment-lines >>"$todo" <<\EOF
147
@@ -252,6 +262,12 @@ pick_one () {
262 output eval git cherry-pick \
263 ${gpg_sign_opt:+$(git rev-parse --sq-quote "$gpg_sign_opt")} \
264 "$strategy_args" $empty_args $ff "$@"
265 +
266 + # If cherry-pick dies it leaves the to-be-picked commit unrecorded. Reschedule
267 + # previous task so this commit is not lost.
268 + ret=$?
269 + case "$ret" in [01]) ;; *) reschedule_last_action ;; esac
270 + return $ret
271 }
272
273 pick_one_preserving_merges () {
t/t3404-rebase-interactive.sh
+47
@@ -1055,4 +1055,51 @@ test_expect_success 'todo count' '
1055 grep "^# Rebase ..* onto ..* ([0-9]" actual
1056 '
1057
1058 +test_expect_success 'rebase -i commits that overwrite untracked files (pick)' '
1059 + git checkout --force branch2 &&
1060 + git clean -f &&
1061 + set_fake_editor &&
1062 + FAKE_LINES="edit 1 2" git rebase -i A &&
1063 + test_cmp_rev HEAD F &&
1064 + test_path_is_missing file6 &&
1065 + >file6 &&
1066 + test_must_fail git rebase --continue &&
1067 + test_cmp_rev HEAD F &&
1068 + rm file6 &&
1069 + git rebase --continue &&
1070 + test_cmp_rev HEAD I
1071 +'
1072 +
1073 +test_expect_success 'rebase -i commits that overwrite untracked files (squash)' '
1074 + git checkout --force branch2 &&
1075 + git clean -f &&
1076 + git tag original-branch2 &&
1077 + set_fake_editor &&
1078 + FAKE_LINES="edit 1 squash 2" git rebase -i A &&
1079 + test_cmp_rev HEAD F &&
1080 + test_path_is_missing file6 &&
1081 + >file6 &&
1082 + test_must_fail git rebase --continue &&
1083 + test_cmp_rev HEAD F &&
1084 + rm file6 &&
1085 + git rebase --continue &&
1086 + test $(git cat-file commit HEAD | sed -ne \$p) = I &&
1087 + git reset --hard original-branch2
1088 +'
1089 +
1090 +test_expect_success 'rebase -i commits that overwrite untracked files (no ff)' '
1091 + git checkout --force branch2 &&
1092 + git clean -f &&
1093 + set_fake_editor &&
1094 + FAKE_LINES="edit 1 2" git rebase -i --no-ff A &&
1095 + test $(git cat-file commit HEAD | sed -ne \$p) = F &&
1096 + test_path_is_missing file6 &&
1097 + >file6 &&
1098 + test_must_fail git rebase --continue &&
1099 + test $(git cat-file commit HEAD | sed -ne \$p) = F &&
1100 + rm file6 &&
1101 + git rebase --continue &&
1102 + test $(git cat-file commit HEAD | sed -ne \$p) = I
1103 +'
1104 +
1105 test_done