From 002ee2fe68258e5a4c6dfa93b1c46cf3318b5342 Mon Sep 17 00:00:00 2001 From: Pratik Karki Date: Tue, 4 Sep 2018 14:59:57 -0700 Subject: builtin rebase: support `keep-empty` option The `--keep-empty` option can be used to keep the commits that do not change anything from its parents in the result. While the scripted version uses `interactive_rebase=implied` to indicate that the rebase needs to use the `git-rebase--interactive` backend in non-interactive mode as fallback when figuring out which backend to use, the C version needs to use a different route because the backend will already be chosen during the `parse_options()` call. Signed-off-by: Pratik Karki Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- builtin/rebase.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/builtin/rebase.c b/builtin/rebase.c index 0f3e156dac..2336b6b979 100644 --- a/builtin/rebase.c +++ b/builtin/rebase.c @@ -95,6 +95,7 @@ struct rebase_options { const char *action; int signoff; int allow_rerere_autoupdate; + int keep_empty; }; static int is_interactive(struct rebase_options *opts) @@ -103,6 +104,23 @@ static int is_interactive(struct rebase_options *opts) opts->type == REBASE_PRESERVE_MERGES; } +static void imply_interactive(struct rebase_options *opts, const char *option) +{ + switch (opts->type) { + case REBASE_AM: + die(_("%s requires an interactive rebase"), option); + break; + case REBASE_INTERACTIVE: + case REBASE_PRESERVE_MERGES: + break; + case REBASE_MERGE: + /* we silently *upgrade* --merge to --interactive if needed */ + default: + opts->type = REBASE_INTERACTIVE; /* implied */ + break; + } +} + /* Returns the filename prefixed by the state_dir */ static const char *state_dir_path(const char *filename, struct rebase_options *opts) { @@ -276,6 +294,7 @@ static int run_specific_rebase(struct rebase_options *opts) opts->allow_rerere_autoupdate < 0 ? "" : opts->allow_rerere_autoupdate ? "--rerere-autoupdate" : "--no-rerere-autoupdate"); + add_var(&script_snippet, "keep_empty", opts->keep_empty ? "yes" : ""); switch (opts->type) { case REBASE_AM: @@ -588,6 +607,8 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) &options.allow_rerere_autoupdate, N_("allow rerere to update index with resolved " "conflict")), + OPT_BOOL('k', "keep-empty", &options.keep_empty, + N_("preserve empty commits during rebase")), OPT_END(), }; @@ -787,6 +808,9 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) options.flags |= REBASE_FORCE; } + if (options.keep_empty) + imply_interactive(&options, "--keep-empty"); + switch (options.type) { case REBASE_MERGE: case REBASE_INTERACTIVE: -- cgit v1.2.3