]> git.ipfire.org Git - thirdparty/git.git/commitdiff
sequencer: fix cleanup with --signoff and -x
authorPhillip Wood <phillip.wood@dunelm.org.uk>
Fri, 29 Mar 2019 11:08:42 +0000 (11:08 +0000)
committerJunio C Hamano <gitster@pobox.com>
Thu, 18 Apr 2019 04:48:42 +0000 (13:48 +0900)
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>
sequencer.c
sequencer.h
t/t3511-cherry-pick-x.sh

index 79a046d748300d76ec66f5fd4cd0cb0e681b5651..ca0d750c75fc529fd53024ae9af3c313bb163012 100644 (file)
@@ -172,17 +172,22 @@ static int git_sequencer_config(const char *k, const char *v, void *cb)
                if (status)
                        return status;
 
-               if (!strcmp(s, "verbatim"))
+               if (!strcmp(s, "verbatim")) {
                        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;
-               else if (!strcmp(s, "strip"))
+                       opts->explicit_cleanup = 1;
+               } else if (!strcmp(s, "strip")) {
                        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;
-               else
+                       opts->explicit_cleanup = 1;
+               } else {
                        warning(_("invalid commit message cleanup mode '%s'"),
                                  s);
+               }
 
                free((char *)s);
                return status;
@@ -1383,8 +1388,13 @@ static int try_to_commit(struct repository *r,
                msg = &commit_msg;
        }
 
-       cleanup = (flags & CLEANUP_MSG) ? COMMIT_MSG_CLEANUP_ALL :
-                                         opts->default_msg_cleanup;
+       if (flags & CLEANUP_MSG)
+               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)
                strbuf_stripspace(msg, cleanup == COMMIT_MSG_CLEANUP_ALL);
index 4d505b3590ed158600844cfe3889112b5da4e511..82bc7a48d588a92ffc4b001a13aa6b65b369ea9e 100644 (file)
@@ -47,6 +47,7 @@ struct replay_opts {
 
        char *gpg_sign;
        enum commit_msg_cleanup_mode default_msg_cleanup;
+       int explicit_cleanup;
 
        /* Merge strategy */
        char *strategy;
index 9888bf34b9538f6e4aae1a1c65022ae126a62ce2..84a587daf3af0356244c58c6472e202875679200 100755 (executable)
@@ -298,4 +298,24 @@ test_expect_success 'cherry-pick preserves commit message' '
        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