Skip to content

Commit d421afa

Browse files
dschogitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 5d826e9 commit d421afa

File tree

8 files changed

+55
-5
lines changed

8 files changed

+55
-5
lines changed

Documentation/git-rebase.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -501,6 +501,11 @@ See also INCOMPATIBLE OPTIONS below.
501501
with care: the final stash application after a successful
502502
rebase might result in non-trivial conflicts.
503503

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+
504509
INCOMPATIBLE OPTIONS
505510
--------------------
506511

builtin/rebase--interactive.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,8 @@ int cmd_rebase__interactive(int argc, const char **argv, const char *prefix)
192192
OPT_STRING(0, "onto-name", &onto_name, N_("onto-name"), N_("onto name")),
193193
OPT_STRING(0, "cmd", &cmd, N_("cmd"), N_("the command to run")),
194194
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")),
195197
OPT_END()
196198
};
197199

builtin/rebase.c

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ struct rebase_options {
104104
int rebase_merges, rebase_cousins;
105105
char *strategy, *strategy_opts;
106106
struct strbuf git_format_patch_opt;
107+
int reschedule_failed_exec;
107108
};
108109

109110
static int is_interactive(struct rebase_options *opts)
@@ -415,6 +416,8 @@ static int run_specific_rebase(struct rebase_options *opts)
415416
argv_array_push(&child.args, opts->gpg_sign_opt);
416417
if (opts->signoff)
417418
argv_array_push(&child.args, "--signoff");
419+
if (opts->reschedule_failed_exec)
420+
argv_array_push(&child.args, "--reschedule-failed-exec");
418421

419422
status = run_command(&child);
420423
goto finished_rebase;
@@ -920,6 +923,9 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
920923
"strategy")),
921924
OPT_BOOL(0, "root", &options.root,
922925
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")),
923929
OPT_END(),
924930
};
925931
int i;
@@ -1216,6 +1222,9 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
12161222
break;
12171223
}
12181224

1225+
if (options.reschedule_failed_exec && !is_interactive(&options))
1226+
die(_("--reschedule-failed-exec requires an interactive rebase"));
1227+
12191228
if (options.git_am_opts.argc) {
12201229
/* all am options except -q are compatible only with --am */
12211230
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)
12411250
options.flags |= REBASE_FORCE;
12421251
}
12431252

1244-
if (options.type == REBASE_PRESERVE_MERGES)
1253+
if (options.type == REBASE_PRESERVE_MERGES) {
12451254
/*
12461255
* Note: incompatibility with --signoff handled in signoff block above
12471256
* Note: incompatibility with --interactive is just a strong warning;
@@ -1251,6 +1260,11 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
12511260
die(_("error: cannot combine '--preserve-merges' with "
12521261
"'--rebase-merges'"));
12531262

1263+
if (options.reschedule_failed_exec)
1264+
die(_("error: cannot combine '--preserve-merges' with "
1265+
"'--reschedule-failed-exec'"));
1266+
}
1267+
12541268
if (options.rebase_merges) {
12551269
if (strategy_options.nr)
12561270
die(_("error: cannot combine '--rebase-merges' with "

git-legacy-rebase.sh

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ skip! skip current patch and continue
4848
edit-todo! edit the todo list during an interactive rebase
4949
quit! abort but keep HEAD where it is
5050
show-current-patch! show the patch file being applied or merged
51+
reschedule-failed-exec automatically reschedule failed exec commands
5152
"
5253
. git-sh-setup
5354
set_reflog_action rebase
@@ -92,6 +93,7 @@ autosquash=
9293
keep_empty=
9394
allow_empty_message=--allow-empty-message
9495
signoff=
96+
reschedule_failed_exec=
9597
test "$(git config --bool rebase.autosquash)" = "true" && autosquash=t
9698
case "$(git config --bool commit.gpgsign)" in
9799
true) gpg_sign_opt=-S ;;
@@ -126,6 +128,8 @@ read_basic_state () {
126128
signoff="$(cat "$state_dir"/signoff)"
127129
force_rebase=t
128130
}
131+
test -f "$state_dir"/reschedule-failed-exec &&
132+
reschedule_failed_exec=t
129133
}
130134

131135
finish_rebase () {
@@ -163,7 +167,8 @@ run_interactive () {
163167
"$allow_empty_message" "$autosquash" "$verbose" \
164168
"$force_rebase" "$onto_name" "$head_name" "$strategy" \
165169
"$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"
167172
}
168173

169174
run_specific_rebase () {
@@ -378,6 +383,12 @@ do
378383
--gpg-sign=*)
379384
gpg_sign_opt="-S${1#--gpg-sign=}"
380385
;;
386+
--reschedule-failed-exec)
387+
reschedule_failed_exec=--reschedule-failed-exec
388+
;;
389+
--no-reschedule-failed-exec)
390+
reschedule_failed_exec=
391+
;;
381392
--)
382393
shift
383394
break
@@ -534,6 +545,9 @@ then
534545
# git-rebase.txt caveats with "unless you know what you are doing"
535546
test -n "$rebase_merges" &&
536547
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'")"
537551
fi
538552

539553
if test -n "$rebase_merges"

git-rebase--common.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ write_basic_state () {
1919
"$state_dir"/allow_rerere_autoupdate
2020
test -n "$gpg_sign_opt" && echo "$gpg_sign_opt" > "$state_dir"/gpg_sign_opt
2121
test -n "$signoff" && echo "$signoff" >"$state_dir"/signoff
22+
test -n "$reschedule_failed_exec" && : > "$state_dir"/reschedule-failed-exec
2223
}
2324

2425
apply_autostash () {

sequencer.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ static GIT_PATH_FUNC(rebase_path_strategy, "rebase-merge/strategy")
158158
static GIT_PATH_FUNC(rebase_path_strategy_opts, "rebase-merge/strategy_opts")
159159
static GIT_PATH_FUNC(rebase_path_allow_rerere_autoupdate, "rebase-merge/allow_rerere_autoupdate")
160160
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")
161162

162163
static int git_sequencer_config(const char *k, const char *v, void *cb)
163164
{
@@ -2362,6 +2363,9 @@ static int read_populate_opts(struct replay_opts *opts)
23622363
opts->signoff = 1;
23632364
}
23642365

2366+
if (file_exists(rebase_path_reschedule_failed_exec()))
2367+
opts->reschedule_failed_exec = 1;
2368+
23652369
read_strategy_opts(opts, &buf);
23662370
strbuf_release(&buf);
23672371

@@ -2443,6 +2447,8 @@ int write_basic_state(struct replay_opts *opts, const char *head_name,
24432447
write_file(rebase_path_gpg_sign_opt(), "-S%s\n", opts->gpg_sign);
24442448
if (opts->signoff)
24452449
write_file(rebase_path_signoff(), "--signoff\n");
2450+
if (opts->reschedule_failed_exec)
2451+
write_file(rebase_path_reschedule_failed_exec(), "%s", "");
24462452

24472453
return 0;
24482454
}
@@ -3586,9 +3592,10 @@ static int pick_commits(struct todo_list *todo_list, struct replay_opts *opts)
35863592
*end_of_arg = saved;
35873593

35883594
/* 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))
35923599
res = error_errno(_("could not stat '%s'"),
35933600
get_todo_path(opts));
35943601
else if (match_stat_data(&todo_list->stat, &st)) {

sequencer.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ struct replay_opts {
3939
int allow_empty_message;
4040
int keep_redundant_commits;
4141
int verbose;
42+
int reschedule_failed_exec;
4243

4344
int mainline;
4445

t/t3418-rebase-continue.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,4 +254,10 @@ test_expect_success 'the todo command "break" works' '
254254
test_path_is_file execed
255255
'
256256

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+
257263
test_done

0 commit comments

Comments
 (0)