Skip to content

Commit dc42e9a

Browse files
phillipwoodgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 1055997 commit dc42e9a

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

sequencer.c

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,24 @@ enum commit_msg_cleanup_mode get_cleanup_mode(const char *cleanup_arg,
535535
die(_("Invalid cleanup mode %s"), cleanup_arg);
536536
}
537537

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+
538556
void append_conflicts_hint(struct index_state *istate,
539557
struct strbuf *msgbuf)
540558
{
@@ -2367,7 +2385,10 @@ static int populate_opts_cb(const char *key, const char *value, void *data)
23672385
opts->allow_rerere_auto =
23682386
git_config_bool_or_int(key, value, &error_flag) ?
23692387
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
23712392
return error(_("invalid key: %s"), key);
23722393

23732394
if (!error_flag)
@@ -2771,6 +2792,11 @@ static int save_opts(struct replay_opts *opts)
27712792
res |= git_config_set_in_file_gently(opts_file, "options.allow-rerere-auto",
27722793
opts->allow_rerere_auto == RERERE_AUTOUPDATE ?
27732794
"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));
27742800
return res;
27752801
}
27762802

0 commit comments

Comments
 (0)