sequencer.c: save and restore cleanup mode
If the user specifies an explicit cleanup mode then save and restore it so that it is preserved by 'git cherry-pick --continue'. Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Phillip Wood committed
Apr 17, 2019 at 11:23 UTC
dc42e9a83a9e9206566b6bc9b57f431b98682b29
1 file changed
+27
-1
sequencer.c
+27
-1
@@ -535,6 +535,24 @@ enum commit_msg_cleanup_mode get_cleanup_mode(const char *cleanup_arg,
535
die(_("Invalid cleanup mode %s"), cleanup_arg);
536
}
537
538
+/*
539
+ * NB using int rather than enum cleanup_mode to stop clang's
540
+ * -Wtautological-constant-out-of-range-compare complaining that the comparison
541
+ * is always true.
542
+ */
543
+static const char *describe_cleanup_mode(int cleanup_mode)
544
+{
545
+ static const char *modes[] = { "whitespace",
546
+ "verbatim",
547
+ "scissors",
548
+ "strip" };
549
+
550
+ if (cleanup_mode < ARRAY_SIZE(modes))
551
+ return modes[cleanup_mode];
552
+
553
+ BUG("invalid cleanup_mode provided (%d)", cleanup_mode);
554
+}
555
+
556
void append_conflicts_hint(struct index_state *istate,
557
struct strbuf *msgbuf)
558
{
@@ -2367,7 +2385,10 @@ static int populate_opts_cb(const char *key, const char *value, void *data)
2385
opts->allow_rerere_auto =
2386
git_config_bool_or_int(key, value, &error_flag) ?
2387
RERERE_AUTOUPDATE : RERERE_NOAUTOUPDATE;
2370
- else
2388
+ else if (!strcmp(key, "options.default-msg-cleanup")) {
2389
+ opts->explicit_cleanup = 1;
2390
+ opts->default_msg_cleanup = get_cleanup_mode(value, 1);
2391
+ } else
2392
return error(_("invalid key: %s"), key);
2393
2394
if (!error_flag)
@@ -2771,6 +2792,11 @@ static int save_opts(struct replay_opts *opts)
2792
res |= git_config_set_in_file_gently(opts_file, "options.allow-rerere-auto",
2793
opts->allow_rerere_auto == RERERE_AUTOUPDATE ?
2794
"true" : "false");
2795
+
2796
+ if (opts->explicit_cleanup)
2797
+ res |= git_config_set_in_file_gently(opts_file,
2798
+ "options.default-msg-cleanup",
2799
+ describe_cleanup_mode(opts->default_msg_cleanup));
2800
return res;
2801
}
2802