Skip to content

Commit 002ee2f

Browse files
prertikgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Johannes Schindelin <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 53f9e5b commit 002ee2f

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

builtin/rebase.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ struct rebase_options {
9595
const char *action;
9696
int signoff;
9797
int allow_rerere_autoupdate;
98+
int keep_empty;
9899
};
99100

100101
static int is_interactive(struct rebase_options *opts)
@@ -103,6 +104,23 @@ static int is_interactive(struct rebase_options *opts)
103104
opts->type == REBASE_PRESERVE_MERGES;
104105
}
105106

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+
106124
/* Returns the filename prefixed by the state_dir */
107125
static const char *state_dir_path(const char *filename, struct rebase_options *opts)
108126
{
@@ -276,6 +294,7 @@ static int run_specific_rebase(struct rebase_options *opts)
276294
opts->allow_rerere_autoupdate < 0 ? "" :
277295
opts->allow_rerere_autoupdate ?
278296
"--rerere-autoupdate" : "--no-rerere-autoupdate");
297+
add_var(&script_snippet, "keep_empty", opts->keep_empty ? "yes" : "");
279298

280299
switch (opts->type) {
281300
case REBASE_AM:
@@ -588,6 +607,8 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
588607
&options.allow_rerere_autoupdate,
589608
N_("allow rerere to update index with resolved "
590609
"conflict")),
610+
OPT_BOOL('k', "keep-empty", &options.keep_empty,
611+
N_("preserve empty commits during rebase")),
591612
OPT_END(),
592613
};
593614

@@ -787,6 +808,9 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
787808
options.flags |= REBASE_FORCE;
788809
}
789810

811+
if (options.keep_empty)
812+
imply_interactive(&options, "--keep-empty");
813+
790814
switch (options.type) {
791815
case REBASE_MERGE:
792816
case REBASE_INTERACTIVE:

0 commit comments

Comments
 (0)