From: Robin Stocker <robin@nibor.org>
To: git@vger.kernel.org
Subject: [PATCH] cherry-pick: Append -x line on separate paragraph
Date: Tue, 4 Sep 2012 19:16:46 +0200 (CEST) [thread overview]
Message-ID: <1244407605.1231.1346779006295.JavaMail.root@bazinga.schuettel.ch> (raw)
In-Reply-To: <739367481.1229.1346778500787.JavaMail.root@bazinga.schuettel.ch>
Before this, git cherry-pick -x resulted in messages like this:
Message of cherry-picked commit
(cherry picked from commit 871e293c9acbeaacce59dcd98fab6028f552f5be)
Which is not the recommended way to write commit messages. When the
commit message ends with a Signed-off-by, it's less bad. But having it
on a line apart from the others also doesn't hurt there.
Now, care is taken that the line is appended as a separate paragraph:
Message of cherry-picked commit
(cherry picked from commit 871e293c9acbeaacce59dcd98fab6028f552f5be)
Because some Git implementations (JGit) don't always terminate the
commit message with a newline, this change also inserts a second newline
if necessary.
Signed-off-by: Robin Stocker <robin@nibor.org>
---
sequencer.c | 4 ++++
t/t3511-cherry-pick-message.sh | 26 ++++++++++++++++++++++++++
2 files changed, 30 insertions(+), 0 deletions(-)
create mode 100755 t/t3511-cherry-pick-message.sh
diff --git a/sequencer.c b/sequencer.c
index bf078f2..41852e6 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -484,6 +484,10 @@ static int do_pick_commit(struct commit *commit, struct replay_opts *opts)
}
if (opts->record_origin) {
+ /* Some implementations don't terminate message with final \n, so add it */
+ if (msg.message[strlen(msg.message)-1] != '\n')
+ strbuf_addch(&msgbuf, '\n');
+ 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/t3511-cherry-pick-message.sh b/t/t3511-cherry-pick-message.sh
new file mode 100755
index 0000000..6aba8b2
--- /dev/null
+++ b/t/t3511-cherry-pick-message.sh
@@ -0,0 +1,26 @@
+#!/bin/sh
+
+test_description='Test cherry-pick commit message with -x'
+
+. ./test-lib.sh
+
+test_expect_success setup '
+ git config advice.detachedhead false &&
+ test_commit initial foo a &&
+ test_commit base foo b &&
+ git checkout initial
+'
+
+test_expect_success 'cherry-pick -x appends message on separate line' '
+ git cherry-pick -x base &&
+ cat >expect <<-\EOF &&
+ base
+
+ (cherry picked from commit 462a97d89aa55720c97984a3ce09665989193981)
+
+ EOF
+ git log --format=%B -n 1 >actual &&
+ test_cmp expect actual
+'
+
+test_done
--
1.7.7.6
next parent reply other threads:[~2012-09-04 17:23 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <739367481.1229.1346778500787.JavaMail.root@bazinga.schuettel.ch>
2012-09-04 17:16 ` Robin Stocker [this message]
2012-09-04 18:43 ` [PATCH] cherry-pick: Append -x line on separate paragraph Junio C Hamano
2012-09-05 20:36 ` Robin Stocker
2012-09-06 3:47 ` Junio C Hamano
2012-09-08 14:10 ` Robin Stocker
2012-09-10 16:27 ` Jeff King
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=1244407605.1231.1346779006295.JavaMail.root@bazinga.schuettel.ch \
--to=robin@nibor.org \
--cc=git@vger.kernel.org \
/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).