builtin rebase: support --rerere-autoupdate
The `--rerere-autoupdate` option allows rerere to update the index with resolved conflicts. This commit follows closely the equivalent part of `git-legacy-rebase.sh`. 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
ead98c111b8a05eb65825f31049e454c8b1ced34
1 file changed
+25
builtin/rebase.c
+25
@@ -94,6 +94,7 @@ struct rebase_options {
94
struct strbuf git_am_opt;
95
const char *action;
96
int signoff;
97
+ int allow_rerere_autoupdate;
98
};
99
100
static int is_interactive(struct rebase_options *opts)
@@ -174,6 +175,21 @@ static int read_basic_state(struct rebase_options *opts)
175
opts->flags |= REBASE_FORCE;
176
}
177
178
+ if (file_exists(state_dir_path("allow_rerere_autoupdate", opts))) {
179
+ strbuf_reset(&buf);
180
+ if (read_one(state_dir_path("allow_rerere_autoupdate", opts),
181
+ &buf))
182
+ return -1;
183
+ if (!strcmp(buf.buf, "--rerere-autoupdate"))
184
+ opts->allow_rerere_autoupdate = 1;
185
+ else if (!strcmp(buf.buf, "--no-rerere-autoupdate"))
186
+ opts->allow_rerere_autoupdate = 0;
187
+ else
188
+ warning(_("ignoring invalid allow_rerere_autoupdate: "
189
+ "'%s'"), buf.buf);
190
+ } else
191
+ opts->allow_rerere_autoupdate = -1;
192
+
193
strbuf_release(&buf);
194
195
return 0;
@@ -256,6 +272,10 @@ static int run_specific_rebase(struct rebase_options *opts)
272
add_var(&script_snippet, "switch_to", opts->switch_to);
273
add_var(&script_snippet, "action", opts->action ? opts->action : "");
274
add_var(&script_snippet, "signoff", opts->signoff ? "--signoff" : "");
275
+ add_var(&script_snippet, "allow_rerere_autoupdate",
276
+ opts->allow_rerere_autoupdate < 0 ? "" :
277
+ opts->allow_rerere_autoupdate ?
278
+ "--rerere-autoupdate" : "--no-rerere-autoupdate");
279
280
switch (opts->type) {
281
case REBASE_AM:
@@ -488,6 +508,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
508
.type = REBASE_UNSPECIFIED,
509
.flags = REBASE_NO_QUIET,
510
.git_am_opt = STRBUF_INIT,
511
+ .allow_rerere_autoupdate = -1,
512
};
513
const char *branch_name;
514
int ret, flags, total_argc, in_progress = 0;
@@ -553,6 +574,10 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
574
OPT_SET_INT('p', "preserve-merges", &options.type,
575
N_("try to recreate merges instead of ignoring "
576
"them"), REBASE_PRESERVE_MERGES),
577
+ OPT_BOOL(0, "rerere-autoupdate",
578
+ &options.allow_rerere_autoupdate,
579
+ N_("allow rerere to update index with resolved "
580
+ "conflict")),
581
OPT_END(),
582
};
583