sequencer: fix cleanup with --signoff and -x

Before commit 356ee4659b ("sequencer: try to commit without forking 'git commit'", 2017-11-24) when --signoff or -x were given on the command line the commit message was cleaned up with --cleanup=space or commit.cleanup if it was set. Unfortunately this behavior was lost when I implemented committing without forking. Fix this and add some tests to catch future regressions. Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Phillip Wood committed Mar 29, 2019 at 11:08 UTC d74f3e58114d1a8544592fcd5dcdfe0fc4993d27
3 files changed +38 -7
sequencer.c
+17 -7
@@ -172,17 +172,22 @@ static int git_sequencer_config(const char *k, const char *v, void *cb)
172 if (status)
173 return status;
174
175 - if (!strcmp(s, "verbatim"))
175 + if (!strcmp(s, "verbatim")) {
176 opts->default_msg_cleanup = COMMIT_MSG_CLEANUP_NONE;
177 - else if (!strcmp(s, "whitespace"))
177 + opts->explicit_cleanup = 1;
178 + } else if (!strcmp(s, "whitespace")) {
179 opts->default_msg_cleanup = COMMIT_MSG_CLEANUP_SPACE;
179 - else if (!strcmp(s, "strip"))
180 + opts->explicit_cleanup = 1;
181 + } else if (!strcmp(s, "strip")) {
182 opts->default_msg_cleanup = COMMIT_MSG_CLEANUP_ALL;
181 - else if (!strcmp(s, "scissors"))
183 + opts->explicit_cleanup = 1;
184 + } else if (!strcmp(s, "scissors")) {
185 opts->default_msg_cleanup = COMMIT_MSG_CLEANUP_SPACE;
183 - else
186 + opts->explicit_cleanup = 1;
187 + } else {
188 warning(_("invalid commit message cleanup mode '%s'"),
189 s);
190 + }
191
192 free((char *)s);
193 return status;
@@ -1383,8 +1388,13 @@ static int try_to_commit(struct repository *r,
1388 msg = &commit_msg;
1389 }
1390
1386 - cleanup = (flags & CLEANUP_MSG) ? COMMIT_MSG_CLEANUP_ALL :
1387 - opts->default_msg_cleanup;
1391 + if (flags & CLEANUP_MSG)
1392 + cleanup = COMMIT_MSG_CLEANUP_ALL;
1393 + else if ((opts->signoff || opts->record_origin) &&
1394 + !opts->explicit_cleanup)
1395 + cleanup = COMMIT_MSG_CLEANUP_SPACE;
1396 + else
1397 + cleanup = opts->default_msg_cleanup;
1398
1399 if (cleanup != COMMIT_MSG_CLEANUP_NONE)
1400 strbuf_stripspace(msg, cleanup == COMMIT_MSG_CLEANUP_ALL);
sequencer.h
+1
@@ -47,6 +47,7 @@ struct replay_opts {
47
48 char *gpg_sign;
49 enum commit_msg_cleanup_mode default_msg_cleanup;
50 + int explicit_cleanup;
51
52 /* Merge strategy */
53 char *strategy;
t/t3511-cherry-pick-x.sh
+20
@@ -298,4 +298,24 @@ test_expect_success 'cherry-pick preserves commit message' '
298 test_cmp expect actual
299 '
300
301 +test_expect_success 'cherry-pick -x cleans commit message' '
302 + pristine_detach initial &&
303 + git cherry-pick -x mesg-unclean &&
304 + git log -1 --pretty=format:%B >actual &&
305 + printf "%s\n(cherry picked from commit %s)\n" \
306 + "$mesg_unclean" $(git rev-parse mesg-unclean) |
307 + git stripspace >expect &&
308 + test_cmp expect actual
309 +'
310 +
311 +test_expect_success 'cherry-pick -x respects commit.cleanup' '
312 + pristine_detach initial &&
313 + git -c commit.cleanup=strip cherry-pick -x mesg-unclean &&
314 + git log -1 --pretty=format:%B >actual &&
315 + printf "%s\n(cherry picked from commit %s)\n" \
316 + "$mesg_unclean" $(git rev-parse mesg-unclean) |
317 + git stripspace -s >expect &&
318 + test_cmp expect actual
319 +'
320 +
321 test_done