Skip to content

Commit 3c3588c

Browse files
prertikgitster
authored andcommitted
builtin rebase: support --rebase-merges[=[no-]rebase-cousins]
The mode to rebase non-linear branches is now supported by the builtin rebase, too. Signed-off-by: Pratik Karki <[email protected]> Signed-off-by: Johannes Schindelin <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 9b3a448 commit 3c3588c

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

builtin/rebase.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ struct rebase_options {
9595
int autostash;
9696
char *cmd;
9797
int allow_empty_message;
98+
int rebase_merges, rebase_cousins;
9899
};
99100

100101
static int is_interactive(struct rebase_options *opts)
@@ -351,6 +352,10 @@ static int run_specific_rebase(struct rebase_options *opts)
351352
add_var(&script_snippet, "cmd", opts->cmd);
352353
add_var(&script_snippet, "allow_empty_message",
353354
opts->allow_empty_message ? "--allow-empty-message" : "");
355+
add_var(&script_snippet, "rebase_merges",
356+
opts->rebase_merges ? "t" : "");
357+
add_var(&script_snippet, "rebase_cousins",
358+
opts->rebase_cousins ? "t" : "");
354359

355360
switch (opts->type) {
356361
case REBASE_AM:
@@ -626,6 +631,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
626631
int opt_c = -1;
627632
struct string_list whitespace = STRING_LIST_INIT_NODUP;
628633
struct string_list exec = STRING_LIST_INIT_NODUP;
634+
const char *rebase_merges = NULL;
629635
struct option builtin_rebase_options[] = {
630636
OPT_STRING(0, "onto", &options.onto_name,
631637
N_("revision"),
@@ -705,6 +711,10 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
705711
OPT_BOOL(0, "allow-empty-message",
706712
&options.allow_empty_message,
707713
N_("allow rebasing commits with empty messages")),
714+
{OPTION_STRING, 'r', "rebase-merges", &rebase_merges,
715+
N_("mode"),
716+
N_("try to rebase merges instead of skipping them"),
717+
PARSE_OPT_OPTARG, NULL, (intptr_t)""},
708718
OPT_END(),
709719
};
710720

@@ -940,6 +950,17 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
940950
options.cmd = xstrdup(buf.buf);
941951
}
942952

953+
if (rebase_merges) {
954+
if (!*rebase_merges)
955+
; /* default mode; do nothing */
956+
else if (!strcmp("rebase-cousins", rebase_merges))
957+
options.rebase_cousins = 1;
958+
else if (strcmp("no-rebase-cousins", rebase_merges))
959+
die(_("Unknown mode: %s"), rebase_merges);
960+
options.rebase_merges = 1;
961+
imply_interactive(&options, "--rebase-merges");
962+
}
963+
943964
switch (options.type) {
944965
case REBASE_MERGE:
945966
case REBASE_INTERACTIVE:

0 commit comments

Comments
 (0)