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 <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 14:59 UTC
002ee2fe68258e5a4c6dfa93b1c46cf3318b5342
1 file changed
+24
builtin/rebase.c
+24
@@ -95,6 +95,7 @@ struct rebase_options {
95
const char *action;
96
int signoff;
97
int allow_rerere_autoupdate;
98
+ int keep_empty;
99
};
100
101
static int is_interactive(struct rebase_options *opts)
@@ -103,6 +104,23 @@ static int is_interactive(struct rebase_options *opts)
104
opts->type == REBASE_PRESERVE_MERGES;
105
}
106
107
+static void imply_interactive(struct rebase_options *opts, const char *option)
108
+{
109
+ switch (opts->type) {
110
+ case REBASE_AM:
111
+ die(_("%s requires an interactive rebase"), option);
112
+ break;
113
+ case REBASE_INTERACTIVE:
114
+ case REBASE_PRESERVE_MERGES:
115
+ break;
116
+ case REBASE_MERGE:
117
+ /* we silently *upgrade* --merge to --interactive if needed */
118
+ default:
119
+ opts->type = REBASE_INTERACTIVE; /* implied */
120
+ break;
121
+ }
122
+}
123
+
124
/* Returns the filename prefixed by the state_dir */
125
static const char *state_dir_path(const char *filename, struct rebase_options *opts)
126
{
@@ -276,6 +294,7 @@ static int run_specific_rebase(struct rebase_options *opts)
294
opts->allow_rerere_autoupdate < 0 ? "" :
295
opts->allow_rerere_autoupdate ?
296
"--rerere-autoupdate" : "--no-rerere-autoupdate");
297
+ add_var(&script_snippet, "keep_empty", opts->keep_empty ? "yes" : "");
298
299
switch (opts->type) {
300
case REBASE_AM:
@@ -588,6 +607,8 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
607
&options.allow_rerere_autoupdate,
608
N_("allow rerere to update index with resolved "
609
"conflict")),
610
+ OPT_BOOL('k', "keep-empty", &options.keep_empty,
611
+ N_("preserve empty commits during rebase")),
612
OPT_END(),
613
};
614
@@ -787,6 +808,9 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
808
options.flags |= REBASE_FORCE;
809
}
810
811
+ if (options.keep_empty)
812
+ imply_interactive(&options, "--keep-empty");
813
+
814
switch (options.type) {
815
case REBASE_MERGE:
816
case REBASE_INTERACTIVE: