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 <predatoram...@gmail.com>
---
 builtin/rebase.c | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/builtin/rebase.c b/builtin/rebase.c
index 42ee040da3..fd9ad8efae 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(0, "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:
-- 
2.18.0

Reply via email to