Merge branch 'pw/sequencer-cleanup-with-signoff-x-fix'

"git cherry-pick" run with the "-x" or the "--signoff" option used
to (and more importantly, ought to) clean up the commit log message
with the --cleanup=space option by default, but this has been
broken since late 2017.  This has been fixed.

* pw/sequencer-cleanup-with-signoff-x-fix:
  sequencer: fix cleanup with --signoff and -x
This commit is contained in:
Junio C Hamano
2019-05-09 00:37:23 +09:00
3 changed files with 38 additions and 7 deletions

View File

@ -171,17 +171,22 @@ static int git_sequencer_config(const char *k, const char *v, void *cb)
if (status) if (status)
return status; return status;
if (!strcmp(s, "verbatim")) if (!strcmp(s, "verbatim")) {
opts->default_msg_cleanup = COMMIT_MSG_CLEANUP_NONE; opts->default_msg_cleanup = COMMIT_MSG_CLEANUP_NONE;
else if (!strcmp(s, "whitespace")) opts->explicit_cleanup = 1;
} else if (!strcmp(s, "whitespace")) {
opts->default_msg_cleanup = COMMIT_MSG_CLEANUP_SPACE; opts->default_msg_cleanup = COMMIT_MSG_CLEANUP_SPACE;
else if (!strcmp(s, "strip")) opts->explicit_cleanup = 1;
} else if (!strcmp(s, "strip")) {
opts->default_msg_cleanup = COMMIT_MSG_CLEANUP_ALL; opts->default_msg_cleanup = COMMIT_MSG_CLEANUP_ALL;
else if (!strcmp(s, "scissors")) opts->explicit_cleanup = 1;
} else if (!strcmp(s, "scissors")) {
opts->default_msg_cleanup = COMMIT_MSG_CLEANUP_SPACE; opts->default_msg_cleanup = COMMIT_MSG_CLEANUP_SPACE;
else opts->explicit_cleanup = 1;
} else {
warning(_("invalid commit message cleanup mode '%s'"), warning(_("invalid commit message cleanup mode '%s'"),
s); s);
}
free((char *)s); free((char *)s);
return status; return status;
@ -1382,8 +1387,13 @@ static int try_to_commit(struct repository *r,
msg = &commit_msg; msg = &commit_msg;
} }
cleanup = (flags & CLEANUP_MSG) ? COMMIT_MSG_CLEANUP_ALL : if (flags & CLEANUP_MSG)
opts->default_msg_cleanup; cleanup = COMMIT_MSG_CLEANUP_ALL;
else if ((opts->signoff || opts->record_origin) &&
!opts->explicit_cleanup)
cleanup = COMMIT_MSG_CLEANUP_SPACE;
else
cleanup = opts->default_msg_cleanup;
if (cleanup != COMMIT_MSG_CLEANUP_NONE) if (cleanup != COMMIT_MSG_CLEANUP_NONE)
strbuf_stripspace(msg, cleanup == COMMIT_MSG_CLEANUP_ALL); strbuf_stripspace(msg, cleanup == COMMIT_MSG_CLEANUP_ALL);

View File

@ -48,6 +48,7 @@ struct replay_opts {
char *gpg_sign; char *gpg_sign;
enum commit_msg_cleanup_mode default_msg_cleanup; enum commit_msg_cleanup_mode default_msg_cleanup;
int explicit_cleanup;
/* Merge strategy */ /* Merge strategy */
char *strategy; char *strategy;

View File

@ -298,4 +298,24 @@ test_expect_success 'cherry-pick preserves commit message' '
test_cmp expect actual test_cmp expect actual
' '
test_expect_success 'cherry-pick -x cleans commit message' '
pristine_detach initial &&
git cherry-pick -x mesg-unclean &&
git log -1 --pretty=format:%B >actual &&
printf "%s\n(cherry picked from commit %s)\n" \
"$mesg_unclean" $(git rev-parse mesg-unclean) |
git stripspace >expect &&
test_cmp expect actual
'
test_expect_success 'cherry-pick -x respects commit.cleanup' '
pristine_detach initial &&
git -c commit.cleanup=strip cherry-pick -x mesg-unclean &&
git log -1 --pretty=format:%B >actual &&
printf "%s\n(cherry picked from commit %s)\n" \
"$mesg_unclean" $(git rev-parse mesg-unclean) |
git stripspace -s >expect &&
test_cmp expect actual
'
test_done test_done