summaryrefslogtreecommitdiff
path: root/builtin
diff options
context:
space:
mode:
authorLibravatar Pratik Karki <predatoramigo@gmail.com>2018-09-04 14:59:57 -0700
committerLibravatar Junio C Hamano <gitster@pobox.com>2018-09-06 11:56:20 -0700
commit002ee2fe68258e5a4c6dfa93b1c46cf3318b5342 (patch)
tree77e2477e507fabf8b1158dc130c3605a3b3e9c81 /builtin
parentbuiltin rebase: support `ignore-date` option (diff)
downloadtgif-002ee2fe68258e5a4c6dfa93b1c46cf3318b5342.tar.xz
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>
Diffstat (limited to 'builtin')
-rw-r--r--builtin/rebase.c24
1 files changed, 24 insertions, 0 deletions
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: