rebase: introduce --reschedule-failed-exec

A common use case for the `--exec` option is to verify that each commit in a topic branch compiles cleanly, via `git rebase -x make <base>`. However, when an `exec` in such a rebase fails, it is not re-scheduled, which in this instance is not particularly helpful. Let's offer a flag to reschedule failed `exec` commands. Based on an idea by Paul Morelle. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Johannes Schindelin committed Dec 10, 2018 at 11:04 UTC d421afa0c66ec6bbd15602d534f77546c516f2a5
8 files changed +55 -5
Documentation/git-rebase.txt
+5
@@ -501,6 +501,11 @@ See also INCOMPATIBLE OPTIONS below.
501 with care: the final stash application after a successful
502 rebase might result in non-trivial conflicts.
503
504 +--reschedule-failed-exec::
505 +--no-reschedule-failed-exec::
506 + Automatically reschedule `exec` commands that failed. This only makes
507 + sense in interactive mode (or when an `--exec` option was provided).
508 +
509 INCOMPATIBLE OPTIONS
510 --------------------
511
builtin/rebase--interactive.c
+2
@@ -192,6 +192,8 @@ int cmd_rebase__interactive(int argc, const char **argv, const char *prefix)
192 OPT_STRING(0, "onto-name", &onto_name, N_("onto-name"), N_("onto name")),
193 OPT_STRING(0, "cmd", &cmd, N_("cmd"), N_("the command to run")),
194 OPT_RERERE_AUTOUPDATE(&opts.allow_rerere_auto),
195 + OPT_BOOL(0, "reschedule-failed-exec", &opts.reschedule_failed_exec,
196 + N_("automatically re-schedule any `exec` that fails")),
197 OPT_END()
198 };
199
builtin/rebase.c
+15 -1
@@ -104,6 +104,7 @@ struct rebase_options {
104 int rebase_merges, rebase_cousins;
105 char *strategy, *strategy_opts;
106 struct strbuf git_format_patch_opt;
107 + int reschedule_failed_exec;
108 };
109
110 static int is_interactive(struct rebase_options *opts)
@@ -415,6 +416,8 @@ static int run_specific_rebase(struct rebase_options *opts)
416 argv_array_push(&child.args, opts->gpg_sign_opt);
417 if (opts->signoff)
418 argv_array_push(&child.args, "--signoff");
419 + if (opts->reschedule_failed_exec)
420 + argv_array_push(&child.args, "--reschedule-failed-exec");
421
422 status = run_command(&child);
423 goto finished_rebase;
@@ -920,6 +923,9 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
923 "strategy")),
924 OPT_BOOL(0, "root", &options.root,
925 N_("rebase all reachable commits up to the root(s)")),
926 + OPT_BOOL(0, "reschedule-failed-exec",
927 + &options.reschedule_failed_exec,
928 + N_("automatically re-schedule any `exec` that fails")),
929 OPT_END(),
930 };
931 int i;
@@ -1216,6 +1222,9 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
1222 break;
1223 }
1224
1225 + if (options.reschedule_failed_exec && !is_interactive(&options))
1226 + die(_("--reschedule-failed-exec requires an interactive rebase"));
1227 +
1228 if (options.git_am_opts.argc) {
1229 /* all am options except -q are compatible only with --am */
1230 for (i = options.git_am_opts.argc - 1; i >= 0; i--)
@@ -1241,7 +1250,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
1250 options.flags |= REBASE_FORCE;
1251 }
1252
1244 - if (options.type == REBASE_PRESERVE_MERGES)
1253 + if (options.type == REBASE_PRESERVE_MERGES) {
1254 /*
1255 * Note: incompatibility with --signoff handled in signoff block above
1256 * Note: incompatibility with --interactive is just a strong warning;
@@ -1251,6 +1260,11 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
1260 die(_("error: cannot combine '--preserve-merges' with "
1261 "'--rebase-merges'"));
1262
1263 + if (options.reschedule_failed_exec)
1264 + die(_("error: cannot combine '--preserve-merges' with "
1265 + "'--reschedule-failed-exec'"));
1266 + }
1267 +
1268 if (options.rebase_merges) {
1269 if (strategy_options.nr)
1270 die(_("error: cannot combine '--rebase-merges' with "
git-legacy-rebase.sh
+15 -1
@@ -48,6 +48,7 @@ skip! skip current patch and continue
48 edit-todo! edit the todo list during an interactive rebase
49 quit! abort but keep HEAD where it is
50 show-current-patch! show the patch file being applied or merged
51 +reschedule-failed-exec automatically reschedule failed exec commands
52 "
53 . git-sh-setup
54 set_reflog_action rebase
@@ -92,6 +93,7 @@ autosquash=
93 keep_empty=
94 allow_empty_message=--allow-empty-message
95 signoff=
96 +reschedule_failed_exec=
97 test "$(git config --bool rebase.autosquash)" = "true" && autosquash=t
98 case "$(git config --bool commit.gpgsign)" in
99 true) gpg_sign_opt=-S ;;
@@ -126,6 +128,8 @@ read_basic_state () {
128 signoff="$(cat "$state_dir"/signoff)"
129 force_rebase=t
130 }
131 + test -f "$state_dir"/reschedule-failed-exec &&
132 + reschedule_failed_exec=t
133 }
134
135 finish_rebase () {
@@ -163,7 +167,8 @@ run_interactive () {
167 "$allow_empty_message" "$autosquash" "$verbose" \
168 "$force_rebase" "$onto_name" "$head_name" "$strategy" \
169 "$strategy_opts" "$cmd" "$switch_to" \
166 - "$allow_rerere_autoupdate" "$gpg_sign_opt" "$signoff"
170 + "$allow_rerere_autoupdate" "$gpg_sign_opt" "$signoff" \
171 + "$reschedule_failed_exec"
172 }
173
174 run_specific_rebase () {
@@ -378,6 +383,12 @@ do
383 --gpg-sign=*)
384 gpg_sign_opt="-S${1#--gpg-sign=}"
385 ;;
386 + --reschedule-failed-exec)
387 + reschedule_failed_exec=--reschedule-failed-exec
388 + ;;
389 + --no-reschedule-failed-exec)
390 + reschedule_failed_exec=
391 + ;;
392 --)
393 shift
394 break
@@ -534,6 +545,9 @@ then
545 # git-rebase.txt caveats with "unless you know what you are doing"
546 test -n "$rebase_merges" &&
547 die "$(gettext "error: cannot combine '--preserve-merges' with '--rebase-merges'")"
548 +
549 + test -n "$reschedule_failed_exec" &&
550 + die "$(gettext "error: cannot combine '--preserve-merges' with '--reschedule-failed-exec'")"
551 fi
552
553 if test -n "$rebase_merges"
git-rebase--common.sh
+1
@@ -19,6 +19,7 @@ write_basic_state () {
19 "$state_dir"/allow_rerere_autoupdate
20 test -n "$gpg_sign_opt" && echo "$gpg_sign_opt" > "$state_dir"/gpg_sign_opt
21 test -n "$signoff" && echo "$signoff" >"$state_dir"/signoff
22 + test -n "$reschedule_failed_exec" && : > "$state_dir"/reschedule-failed-exec
23 }
24
25 apply_autostash () {
sequencer.c
+10 -3
@@ -158,6 +158,7 @@ static GIT_PATH_FUNC(rebase_path_strategy, "rebase-merge/strategy")
158 static GIT_PATH_FUNC(rebase_path_strategy_opts, "rebase-merge/strategy_opts")
159 static GIT_PATH_FUNC(rebase_path_allow_rerere_autoupdate, "rebase-merge/allow_rerere_autoupdate")
160 static GIT_PATH_FUNC(rebase_path_quiet, "rebase-merge/quiet")
161 +static GIT_PATH_FUNC(rebase_path_reschedule_failed_exec, "rebase-merge/reschedule-failed-exec")
162
163 static int git_sequencer_config(const char *k, const char *v, void *cb)
164 {
@@ -2362,6 +2363,9 @@ static int read_populate_opts(struct replay_opts *opts)
2363 opts->signoff = 1;
2364 }
2365
2366 + if (file_exists(rebase_path_reschedule_failed_exec()))
2367 + opts->reschedule_failed_exec = 1;
2368 +
2369 read_strategy_opts(opts, &buf);
2370 strbuf_release(&buf);
2371
@@ -2443,6 +2447,8 @@ int write_basic_state(struct replay_opts *opts, const char *head_name,
2447 write_file(rebase_path_gpg_sign_opt(), "-S%s\n", opts->gpg_sign);
2448 if (opts->signoff)
2449 write_file(rebase_path_signoff(), "--signoff\n");
2450 + if (opts->reschedule_failed_exec)
2451 + write_file(rebase_path_reschedule_failed_exec(), "%s", "");
2452
2453 return 0;
2454 }
@@ -3586,9 +3592,10 @@ static int pick_commits(struct todo_list *todo_list, struct replay_opts *opts)
3592 *end_of_arg = saved;
3593
3594 /* Reread the todo file if it has changed. */
3589 - if (res)
3590 - ; /* fall through */
3591 - else if (stat(get_todo_path(opts), &st))
3595 + if (res) {
3596 + if (opts->reschedule_failed_exec)
3597 + reschedule = 1;
3598 + } else if (stat(get_todo_path(opts), &st))
3599 res = error_errno(_("could not stat '%s'"),
3600 get_todo_path(opts));
3601 else if (match_stat_data(&todo_list->stat, &st)) {
sequencer.h
+1
@@ -39,6 +39,7 @@ struct replay_opts {
39 int allow_empty_message;
40 int keep_redundant_commits;
41 int verbose;
42 + int reschedule_failed_exec;
43
44 int mainline;
45
t/t3418-rebase-continue.sh
+6
@@ -254,4 +254,10 @@ test_expect_success 'the todo command "break" works' '
254 test_path_is_file execed
255 '
256
257 +test_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 +'
262 +
263 test_done