Skip to content

Commit d74f3e5

Browse files
phillipwoodgitster
authored andcommitted
sequencer: fix cleanup with --signoff and -x
Before commit 356ee46 ("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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent ffac537 commit d74f3e5

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
@@ -172,17 +172,22 @@ static int git_sequencer_config(const char *k, const char *v, void *cb)
172172
if (status)
173173
return status;
174174

175-
if (!strcmp(s, "verbatim"))
175+
if (!strcmp(s, "verbatim")) {
176176
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")) {
178179
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")) {
180182
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")) {
182185
opts->default_msg_cleanup = COMMIT_MSG_CLEANUP_SPACE;
183-
else
186+
opts->explicit_cleanup = 1;
187+
} else {
184188
warning(_("invalid commit message cleanup mode '%s'"),
185189
s);
190+
}
186191

187192
free((char *)s);
188193
return status;
@@ -1383,8 +1388,13 @@ static int try_to_commit(struct repository *r,
13831388
msg = &commit_msg;
13841389
}
13851390

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;
13881398

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

sequencer.h

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

4848
char *gpg_sign;
4949
enum commit_msg_cleanup_mode default_msg_cleanup;
50+
int explicit_cleanup;
5051

5152
/* Merge strategy */
5253
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)