Skip to content

Commit f757794

Browse files
committed
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
2 parents 3d67555 + d74f3e5 commit f757794

File tree

3 files changed

+38
-7
lines changed

3 files changed

+38
-7
lines changed

sequencer.c

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -171,17 +171,22 @@ static int git_sequencer_config(const char *k, const char *v, void *cb)
171171
if (status)
172172
return status;
173173

174-
if (!strcmp(s, "verbatim"))
174+
if (!strcmp(s, "verbatim")) {
175175
opts->default_msg_cleanup = COMMIT_MSG_CLEANUP_NONE;
176-
else if (!strcmp(s, "whitespace"))
176+
opts->explicit_cleanup = 1;
177+
} else if (!strcmp(s, "whitespace")) {
177178
opts->default_msg_cleanup = COMMIT_MSG_CLEANUP_SPACE;
178-
else if (!strcmp(s, "strip"))
179+
opts->explicit_cleanup = 1;
180+
} else if (!strcmp(s, "strip")) {
179181
opts->default_msg_cleanup = COMMIT_MSG_CLEANUP_ALL;
180-
else if (!strcmp(s, "scissors"))
182+
opts->explicit_cleanup = 1;
183+
} else if (!strcmp(s, "scissors")) {
181184
opts->default_msg_cleanup = COMMIT_MSG_CLEANUP_SPACE;
182-
else
185+
opts->explicit_cleanup = 1;
186+
} else {
183187
warning(_("invalid commit message cleanup mode '%s'"),
184188
s);
189+
}
185190

186191
free((char *)s);
187192
return status;
@@ -1382,8 +1387,13 @@ static int try_to_commit(struct repository *r,
13821387
msg = &commit_msg;
13831388
}
13841389

1385-
cleanup = (flags & CLEANUP_MSG) ? COMMIT_MSG_CLEANUP_ALL :
1386-
opts->default_msg_cleanup;
1390+
if (flags & CLEANUP_MSG)
1391+
cleanup = COMMIT_MSG_CLEANUP_ALL;
1392+
else if ((opts->signoff || opts->record_origin) &&
1393+
!opts->explicit_cleanup)
1394+
cleanup = COMMIT_MSG_CLEANUP_SPACE;
1395+
else
1396+
cleanup = opts->default_msg_cleanup;
13871397

13881398
if (cleanup != COMMIT_MSG_CLEANUP_NONE)
13891399
strbuf_stripspace(msg, cleanup == COMMIT_MSG_CLEANUP_ALL);

sequencer.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ struct replay_opts {
4848

4949
char *gpg_sign;
5050
enum commit_msg_cleanup_mode default_msg_cleanup;
51+
int explicit_cleanup;
5152

5253
/* Merge strategy */
5354
char *strategy;

t/t3511-cherry-pick-x.sh

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,4 +298,24 @@ test_expect_success 'cherry-pick preserves commit message' '
298298
test_cmp expect actual
299299
'
300300

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+
301321
test_done

0 commit comments

Comments
 (0)