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 <predatoramigo@gmail.com> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Pratik Karki committed Sep 4, 2018 at 15:00 UTC 3c3588c7d33456e76d0ed7b881378ee575f4dc45
1 file changed +21
builtin/rebase.c
+21
@@ -95,6 +95,7 @@ struct rebase_options {
95 int autostash;
96 char *cmd;
97 int allow_empty_message;
98 + int rebase_merges, rebase_cousins;
99 };
100
101 static int is_interactive(struct rebase_options *opts)
@@ -351,6 +352,10 @@ static int run_specific_rebase(struct rebase_options *opts)
352 add_var(&script_snippet, "cmd", opts->cmd);
353 add_var(&script_snippet, "allow_empty_message",
354 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" : "");
359
360 switch (opts->type) {
361 case REBASE_AM:
@@ -626,6 +631,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
631 int opt_c = -1;
632 struct string_list whitespace = STRING_LIST_INIT_NODUP;
633 struct string_list exec = STRING_LIST_INIT_NODUP;
634 + const char *rebase_merges = NULL;
635 struct option builtin_rebase_options[] = {
636 OPT_STRING(0, "onto", &options.onto_name,
637 N_("revision"),
@@ -705,6 +711,10 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
711 OPT_BOOL(0, "allow-empty-message",
712 &options.allow_empty_message,
713 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)""},
718 OPT_END(),
719 };
720
@@ -940,6 +950,17 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
950 options.cmd = xstrdup(buf.buf);
951 }
952
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 +
964 switch (options.type) {
965 case REBASE_MERGE:
966 case REBASE_INTERACTIVE: