Skip to content

Commit d9d9ab0

Browse files
committed
Merge branch 'js/rebase-i-redo-exec'
"git rebase -i" learned to re-execute a command given with 'exec' to run after it failed the last time. * js/rebase-i-redo-exec: rebase: introduce a shortcut for --reschedule-failed-exec rebase: add a config option to default to --reschedule-failed-exec rebase: introduce --reschedule-failed-exec
2 parents 61c51ac + 81ef8ee commit d9d9ab0

File tree

9 files changed

+108
-5
lines changed

9 files changed

+108
-5
lines changed

Documentation/config/rebase.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,8 @@ instead of:
6464
-------------------------------------------
6565
+
6666
Defaults to false.
67+
68+
rebase.rescheduleFailedExec::
69+
Automatically reschedule `exec` commands that failed. This only makes
70+
sense in interactive mode (or when an `--exec` option was provided).
71+
This is the same as specifying the `--reschedule-failed-exec` option.

Documentation/git-rebase.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,12 @@ without an explicit `--interactive`.
462462
+
463463
See also INCOMPATIBLE OPTIONS below.
464464

465+
-y <cmd>::
466+
This is the same as passing `--reschedule-failed-exec` before
467+
`-x <cmd>`, i.e. it appends the specified `exec` command and
468+
turns on the mode where failed `exec` commands are automatically
469+
rescheduled.
470+
465471
--root::
466472
Rebase all commits reachable from <branch>, instead of
467473
limiting them with an <upstream>. This allows you to rebase
@@ -501,6 +507,11 @@ See also INCOMPATIBLE OPTIONS below.
501507
with care: the final stash application after a successful
502508
rebase might result in non-trivial conflicts.
503509

510+
--reschedule-failed-exec::
511+
--no-reschedule-failed-exec::
512+
Automatically reschedule `exec` commands that failed. This only makes
513+
sense in interactive mode (or when an `--exec` option was provided).
514+
504515
INCOMPATIBLE OPTIONS
505516
--------------------
506517

builtin/rebase--interactive.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,8 @@ int cmd_rebase__interactive(int argc, const char **argv, const char *prefix)
193193
OPT_STRING(0, "onto-name", &onto_name, N_("onto-name"), N_("onto name")),
194194
OPT_STRING(0, "cmd", &cmd, N_("cmd"), N_("the command to run")),
195195
OPT_RERERE_AUTOUPDATE(&opts.allow_rerere_auto),
196+
OPT_BOOL(0, "reschedule-failed-exec", &opts.reschedule_failed_exec,
197+
N_("automatically re-schedule any `exec` that fails")),
196198
OPT_END()
197199
};
198200

builtin/rebase.c

Lines changed: 41 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;
@@ -674,6 +677,11 @@ static int rebase_config(const char *var, const char *value, void *data)
674677
return 0;
675678
}
676679

680+
if (!strcmp(var, "rebase.reschedulefailedexec")) {
681+
opts->reschedule_failed_exec = git_config_bool(var, value);
682+
return 0;
683+
}
684+
677685
return git_default_config(var, value, data);
678686
}
679687

@@ -746,6 +754,23 @@ static int parse_opt_interactive(const struct option *opt, const char *arg,
746754
return 0;
747755
}
748756

757+
struct opt_y {
758+
struct string_list *list;
759+
struct rebase_options *options;
760+
};
761+
762+
static int parse_opt_y(const struct option *opt, const char *arg, int unset)
763+
{
764+
struct opt_y *o = opt->value;
765+
766+
if (unset || !arg)
767+
return -1;
768+
769+
o->options->reschedule_failed_exec = 1;
770+
string_list_append(o->list, arg);
771+
return 0;
772+
}
773+
749774
static void NORETURN error_on_missing_default_upstream(void)
750775
{
751776
struct branch *current_branch = branch_get(NULL);
@@ -826,6 +851,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
826851
struct string_list strategy_options = STRING_LIST_INIT_NODUP;
827852
struct object_id squash_onto;
828853
char *squash_onto_name = NULL;
854+
struct opt_y opt_y = { .list = &exec, .options = &options };
829855
struct option builtin_rebase_options[] = {
830856
OPT_STRING(0, "onto", &options.onto_name,
831857
N_("revision"),
@@ -903,6 +929,9 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
903929
OPT_STRING_LIST('x', "exec", &exec, N_("exec"),
904930
N_("add exec lines after each commit of the "
905931
"editable list")),
932+
{ OPTION_CALLBACK, 'y', NULL, &opt_y, N_("<cmd>"),
933+
N_("same as --reschedule-failed-exec -x <cmd>"),
934+
PARSE_OPT_NONEG, parse_opt_y },
906935
OPT_BOOL(0, "allow-empty-message",
907936
&options.allow_empty_message,
908937
N_("allow rebasing commits with empty messages")),
@@ -920,6 +949,9 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
920949
"strategy")),
921950
OPT_BOOL(0, "root", &options.root,
922951
N_("rebase all reachable commits up to the root(s)")),
952+
OPT_BOOL(0, "reschedule-failed-exec",
953+
&options.reschedule_failed_exec,
954+
N_("automatically re-schedule any `exec` that fails")),
923955
OPT_END(),
924956
};
925957
int i;
@@ -1216,6 +1248,9 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
12161248
break;
12171249
}
12181250

1251+
if (options.reschedule_failed_exec && !is_interactive(&options))
1252+
die(_("--reschedule-failed-exec requires an interactive rebase"));
1253+
12191254
if (options.git_am_opts.argc) {
12201255
/* all am options except -q are compatible only with --am */
12211256
for (i = options.git_am_opts.argc - 1; i >= 0; i--)
@@ -1241,7 +1276,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
12411276
options.flags |= REBASE_FORCE;
12421277
}
12431278

1244-
if (options.type == REBASE_PRESERVE_MERGES)
1279+
if (options.type == REBASE_PRESERVE_MERGES) {
12451280
/*
12461281
* Note: incompatibility with --signoff handled in signoff block above
12471282
* Note: incompatibility with --interactive is just a strong warning;
@@ -1251,6 +1286,11 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
12511286
die(_("error: cannot combine '--preserve-merges' with "
12521287
"'--rebase-merges'"));
12531288

1289+
if (options.reschedule_failed_exec)
1290+
die(_("error: cannot combine '--preserve-merges' with "
1291+
"'--reschedule-failed-exec'"));
1292+
}
1293+
12541294
if (options.rebase_merges) {
12551295
if (strategy_options.nr)
12561296
die(_("error: cannot combine '--rebase-merges' with "

git-legacy-rebase.sh

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ f,force-rebase! cherry-pick all commits, even if unchanged
2626
m,merge! use merging strategies to rebase
2727
i,interactive! let the user edit the list of commits to rebase
2828
x,exec=! add exec lines after each commit of the editable list
29+
y=! same as --reschedule-failed-exec -x
2930
k,keep-empty preserve empty commits during rebase
3031
allow-empty-message allow rebasing commits with empty messages
3132
stat! display a diffstat of what changed upstream
@@ -48,6 +49,7 @@ skip! skip current patch and continue
4849
edit-todo! edit the todo list during an interactive rebase
4950
quit! abort but keep HEAD where it is
5051
show-current-patch! show the patch file being applied or merged
52+
reschedule-failed-exec automatically reschedule failed exec commands
5153
"
5254
. git-sh-setup
5355
set_reflog_action rebase
@@ -92,11 +94,14 @@ autosquash=
9294
keep_empty=
9395
allow_empty_message=--allow-empty-message
9496
signoff=
97+
reschedule_failed_exec=
9598
test "$(git config --bool rebase.autosquash)" = "true" && autosquash=t
9699
case "$(git config --bool commit.gpgsign)" in
97100
true) gpg_sign_opt=-S ;;
98101
*) gpg_sign_opt= ;;
99102
esac
103+
test "$(git config --bool rebase.reschedulefailedexec)" = "true" &&
104+
reschedule_failed_exec=--reschedule-failed-exec
100105
. git-rebase--common
101106

102107
read_basic_state () {
@@ -126,6 +131,8 @@ read_basic_state () {
126131
signoff="$(cat "$state_dir"/signoff)"
127132
force_rebase=t
128133
}
134+
test -f "$state_dir"/reschedule-failed-exec &&
135+
reschedule_failed_exec=t
129136
}
130137

131138
finish_rebase () {
@@ -163,7 +170,8 @@ run_interactive () {
163170
"$allow_empty_message" "$autosquash" "$verbose" \
164171
"$force_rebase" "$onto_name" "$head_name" "$strategy" \
165172
"$strategy_opts" "$cmd" "$switch_to" \
166-
"$allow_rerere_autoupdate" "$gpg_sign_opt" "$signoff"
173+
"$allow_rerere_autoupdate" "$gpg_sign_opt" "$signoff" \
174+
"$reschedule_failed_exec"
167175
}
168176

169177
run_specific_rebase () {
@@ -255,6 +263,11 @@ do
255263
cmd="${cmd}exec ${1#--exec=}${LF}"
256264
test -z "$interactive_rebase" && interactive_rebase=implied
257265
;;
266+
-y*)
267+
reschedule_failed_exec=--reschedule-failed-exec
268+
cmd="${cmd}exec ${1#-y}${LF}"
269+
test -z "$interactive_rebase" && interactive_rebase=implied
270+
;;
258271
--interactive)
259272
interactive_rebase=explicit
260273
;;
@@ -378,6 +391,12 @@ do
378391
--gpg-sign=*)
379392
gpg_sign_opt="-S${1#--gpg-sign=}"
380393
;;
394+
--reschedule-failed-exec)
395+
reschedule_failed_exec=--reschedule-failed-exec
396+
;;
397+
--no-reschedule-failed-exec)
398+
reschedule_failed_exec=
399+
;;
381400
--)
382401
shift
383402
break
@@ -534,6 +553,9 @@ then
534553
# git-rebase.txt caveats with "unless you know what you are doing"
535554
test -n "$rebase_merges" &&
536555
die "$(gettext "error: cannot combine '--preserve-merges' with '--rebase-merges'")"
556+
557+
test -n "$reschedule_failed_exec" &&
558+
die "$(gettext "error: cannot combine '--preserve-merges' with '--reschedule-failed-exec'")"
537559
fi
538560

539561
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
{
@@ -2394,6 +2395,9 @@ static int read_populate_opts(struct replay_opts *opts)
23942395
opts->signoff = 1;
23952396
}
23962397

2398+
if (file_exists(rebase_path_reschedule_failed_exec()))
2399+
opts->reschedule_failed_exec = 1;
2400+
23972401
read_strategy_opts(opts, &buf);
23982402
strbuf_release(&buf);
23992403

@@ -2475,6 +2479,8 @@ int write_basic_state(struct replay_opts *opts, const char *head_name,
24752479
write_file(rebase_path_gpg_sign_opt(), "-S%s\n", opts->gpg_sign);
24762480
if (opts->signoff)
24772481
write_file(rebase_path_signoff(), "--signoff\n");
2482+
if (opts->reschedule_failed_exec)
2483+
write_file(rebase_path_reschedule_failed_exec(), "%s", "");
24782484

24792485
return 0;
24802486
}
@@ -3632,9 +3638,10 @@ static int pick_commits(struct repository *r,
36323638
*end_of_arg = saved;
36333639

36343640
/* Reread the todo file if it has changed. */
3635-
if (res)
3636-
; /* fall through */
3637-
else if (stat(get_todo_path(opts), &st))
3641+
if (res) {
3642+
if (opts->reschedule_failed_exec)
3643+
reschedule = 1;
3644+
} else if (stat(get_todo_path(opts), &st))
36383645
res = error_errno(_("could not stat '%s'"),
36393646
get_todo_path(opts));
36403647
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
@@ -40,6 +40,7 @@ struct replay_opts {
4040
int allow_empty_message;
4141
int keep_redundant_commits;
4242
int verbose;
43+
int reschedule_failed_exec;
4344

4445
int mainline;
4546

t/t3418-rebase-continue.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,4 +254,18 @@ 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+
git rebase --abort &&
262+
test_must_fail git -c rebase.rescheduleFailedExec=true \
263+
rebase -x false HEAD^ 2>err &&
264+
grep "^exec false" .git/rebase-merge/git-rebase-todo &&
265+
test_i18ngrep "has been rescheduled" err &&
266+
git rebase --abort &&
267+
test_must_fail git rebase -y false HEAD^ 2>err &&
268+
test_i18ngrep "has been rescheduled" err
269+
'
270+
257271
test_done

0 commit comments

Comments
 (0)