Skip to content

Commit 81ef8ee

Browse files
dschogitster
authored andcommitted
rebase: introduce a shortcut for --reschedule-failed-exec
It is a bit cumbersome to write out the `--reschedule-failed-exec` option before `-x <cmd>` all the time; let's introduce a convenient option to do both at the same time: `-y <cmd>`. Signed-off-by: Johannes Schindelin <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 969de3f commit 81ef8ee

File tree

4 files changed

+36
-0
lines changed

4 files changed

+36
-0
lines changed

Documentation/git-rebase.txt

Lines changed: 6 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

builtin/rebase.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -754,6 +754,23 @@ static int parse_opt_interactive(const struct option *opt, const char *arg,
754754
return 0;
755755
}
756756

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+
757774
static void NORETURN error_on_missing_default_upstream(void)
758775
{
759776
struct branch *current_branch = branch_get(NULL);
@@ -834,6 +851,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
834851
struct string_list strategy_options = STRING_LIST_INIT_NODUP;
835852
struct object_id squash_onto;
836853
char *squash_onto_name = NULL;
854+
struct opt_y opt_y = { .list = &exec, .options = &options };
837855
struct option builtin_rebase_options[] = {
838856
OPT_STRING(0, "onto", &options.onto_name,
839857
N_("revision"),
@@ -911,6 +929,9 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
911929
OPT_STRING_LIST('x', "exec", &exec, N_("exec"),
912930
N_("add exec lines after each commit of the "
913931
"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 },
914935
OPT_BOOL(0, "allow-empty-message",
915936
&options.allow_empty_message,
916937
N_("allow rebasing commits with empty messages")),

git-legacy-rebase.sh

Lines changed: 6 additions & 0 deletions
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
@@ -262,6 +263,11 @@ do
262263
cmd="${cmd}exec ${1#--exec=}${LF}"
263264
test -z "$interactive_rebase" && interactive_rebase=implied
264265
;;
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+
;;
265271
--interactive)
266272
interactive_rebase=explicit
267273
;;

t/t3418-rebase-continue.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,9 @@ test_expect_success '--reschedule-failed-exec' '
262262
test_must_fail git -c rebase.rescheduleFailedExec=true \
263263
rebase -x false HEAD^ 2>err &&
264264
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 &&
265268
test_i18ngrep "has been rescheduled" err
266269
'
267270

0 commit comments

Comments
 (0)