sequencer: preserve commit messages
sequencer calls "commit" with default options, which implies "--cleanup=default" unless the user specified something else in their config. This leads to cherry-picked commits getting a cleaned up commit message, which is usually not an intended side-effect. Make the sequencer use "--cleanup=verbatim" so that it preserves commit messages independent of the default, unless the user has set config for "commit" or the message is amended with -s or -x. Reported-by: Christoph Anton Mitterer <calestyo@scientia.net> Signed-off-by: Michael J Gruber <git@drmicha.warpmail.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Michael J Gruber committed
Mar 6, 2015 at 14:55 UTC
17d65f03e1d2d1678d9960a4f71e4caccacf500f
2 files changed
+33
sequencer.c
+5
@@ -358,6 +358,7 @@ static int run_git_commit(const char *defmsg, struct replay_opts *opts,
358
struct argv_array array;
359
int rc;
360
char *gpg_sign;
361
+ const char *value;
362
363
argv_array_init(&array);
364
argv_array_push(&array, "commit");
@@ -374,6 +375,10 @@ static int run_git_commit(const char *defmsg, struct replay_opts *opts,
375
if (!opts->edit) {
376
argv_array_push(&array, "-F");
377
argv_array_push(&array, defmsg);
378
+ if (!opts->signoff &&
379
+ !opts->record_origin &&
380
+ git_config_get_value("commit.cleanup", &value))
381
+ argv_array_push(&array, "--cleanup=verbatim");
382
}
383
384
if (allow_empty)
t/t3511-cherry-pick-x.sh
+28
@@ -36,6 +36,20 @@ mesg_with_cherry_footer="$mesg_with_footer_sob
36
(cherry picked from commit da39a3ee5e6b4b0d3255bfef95601890afd80709)
37
Tested-by: C.U. Thor <cuthor@example.com>"
38
39
+mesg_unclean="$mesg_one_line
40
+
41
+
42
+leading empty lines
43
+
44
+
45
+consecutive empty lines
46
+
47
+# hash tag comment
48
+
49
+trailing empty lines
50
+
51
+
52
+"
53
54
test_expect_success setup '
55
git config advice.detachedhead false &&
@@ -53,6 +67,10 @@ test_expect_success setup '
67
test_commit "$mesg_with_footer_sob" foo b mesg-with-footer-sob &&
68
git reset --hard initial &&
69
test_commit "$mesg_with_cherry_footer" foo b mesg-with-cherry-footer &&
70
+ git reset --hard initial &&
71
+ test_config commit.cleanup verbatim &&
72
+ test_commit "$mesg_unclean" foo b mesg-unclean &&
73
+ test_unconfig commit.cleanup &&
74
pristine_detach initial &&
75
test_commit conflicting unrelated
76
'
@@ -216,4 +234,14 @@ test_expect_success 'cherry-pick -x -s treats "(cherry picked from..." line as p
234
test_cmp expect actual
235
'
236
237
+test_expect_success 'cherry-pick preserves commit message' '
238
+ pristine_detach initial &&
239
+ printf "$mesg_unclean" >expect &&
240
+ git log -1 --pretty=format:%B mesg-unclean >actual &&
241
+ test_cmp expect actual &&
242
+ git cherry-pick mesg-unclean &&
243
+ git log -1 --pretty=format:%B >actual &&
244
+ test_cmp expect actual
245
+'
246
+
247
test_done