From: Miklos Vajna <vmiklos@suse.cz>
To: Junio C Hamano <gitster@pobox.com>
Cc: git@vger.kernel.org
Subject: [PATCH] cherry-pick -x: improve handling of one-liner commit messages
Date: Fri, 29 Mar 2013 16:38:18 +0100 [thread overview]
Message-ID: <20130329153818.GB27251@suse.cz> (raw)
git cherry-pick -x normally just appends the "cherry picked from commit"
line at the end of the message, which is fine. However, in case the
original commit message had only one line, first append a newline,
otherwise the second line won't be empty, which is against
recommendations.
---
sequencer.c | 10 ++++++++++
t/t3501-revert-cherry-pick.sh | 8 ++++++++
2 files changed, 18 insertions(+)
diff --git a/sequencer.c b/sequencer.c
index aef5e8a..1ae0e43 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -496,6 +496,16 @@ static int do_pick_commit(struct commit *commit, struct replay_opts *opts)
}
if (opts->record_origin) {
+
+ /*
+ * If this the message is a one-liner, append a
+ * newline, so the second line will be empty, as
+ * recommended.
+ */
+ p = strstr(msgbuf.buf, "\n\n");
+ if (!p)
+ strbuf_addch(&msgbuf, '\n');
+
strbuf_addstr(&msgbuf, "(cherry picked from commit ");
strbuf_addstr(&msgbuf, sha1_to_hex(commit->object.sha1));
strbuf_addstr(&msgbuf, ")\n");
diff --git a/t/t3501-revert-cherry-pick.sh b/t/t3501-revert-cherry-pick.sh
index 6f489e2..858c744 100755
--- a/t/t3501-revert-cherry-pick.sh
+++ b/t/t3501-revert-cherry-pick.sh
@@ -70,6 +70,14 @@ test_expect_success 'cherry-pick after renaming branch' '
'
+test_expect_success 'cherry-pick -x of one-liner commit message' '
+
+ git checkout rename2 &&
+ git cherry-pick -x added &&
+ git show -s --pretty=format:%s | test_must_fail grep "cherry picked"
+
+'
+
test_expect_success 'revert after renaming branch' '
git checkout rename1 &&
--
1.8.1.4
next reply other threads:[~2013-03-29 15:38 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-03-29 15:38 Miklos Vajna [this message]
2013-03-29 17:23 ` [PATCH] cherry-pick -x: improve handling of one-liner commit messages Junio C Hamano
2013-03-29 17:41 ` Brandon Casey
2013-03-29 20:39 ` Miklos Vajna
2013-03-29 20:49 ` Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20130329153818.GB27251@suse.cz \
--to=vmiklos@suse.cz \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).