Skip to contentSkip to conversation

cherry-pick -x: improve handling of one-liner commit messages

PATCH In review Miklos Vajna 3 participants 5 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 cherry-pick -x: improve handling of one-liner commit messages

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(+)
sequencer.c +10 -0
index aef5e8a..1ae0e43 100644
@@ -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");
t/t3501-revert-cherry-pick.sh +8 -0
index 6f489e2..858c744 100755
@@ -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 &&
Signature · 1 line
1.8.1.4
#1 lore raw
Quoted 6 lines · Miklos Vajna

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.
---

Sign-off?

I think this is part of the bc/append-signed-off-by topic that is about to graduate to 'master'; more specifically, b971e04f54e7 (sequencer.c: always separate "(cherry picked from" from commit body, 2013-02-12) does the equivalent, no?

Quoted 44 lines
 sequencer.c                   | 10 ++++++++++
 t/t3501-revert-cherry-pick.sh |  8 ++++++++
 2 files changed, 18 insertions(+)
sequencer.c +10 -0
index aef5e8a..1ae0e43 100644
@@ -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");
t/t3501-revert-cherry-pick.sh +8 -0
index 6f489e2..858c744 100755
@@ -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 &&
#2 lore raw
Quoted 9 lines · Junio C Hamano
Quoted 6 lines · Miklos Vajna

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.
---

Quoted 6 lines

Sign-off?

I think this is part of the bc/append-signed-off-by topic that is about to graduate to 'master'; more specifically, b971e04f54e7 (sequencer.c: always separate "(cherry picked from" from commit body, 2013-02-12) does the equivalent, no?

Yeah, I think this case is already handled.

Miklos, can you check out next and see if your problem case is handled?

-Brandon

#3 lore raw

Hi,

Quoted 1 line · Brandon Casey
Quoted 1 line

Sign-off?

Indeed, I forgot about it, my bad.

Quoted 8 lines
Quoted 4 lines

I think this is part of the bc/append-signed-off-by topic that is about to graduate to 'master'; more specifically, b971e04f54e7 (sequencer.c: always separate "(cherry picked from" from commit body, 2013-02-12) does the equivalent, no?

Yeah, I think this case is already handled.

Miklos, can you check out next and see if your problem case is handled?

I just checked next and right, that solves the problem I was fixing.

So -- sorry for the noise. :-)

Miklos

#4 lore raw
Quoted 7 lines · Miklos Vajna
Quoted 5 lines · Brandon Casey
Quoted 4 lines

I think this is part of the bc/append-signed-off-by topic that is about to graduate to 'master'; more specifically, b971e04f54e7 (sequencer.c: always separate "(cherry picked from" from commit body, 2013-02-12) does the equivalent, no?

Quoted 7 lines
Quoted 3 lines

Yeah, I think this case is already handled.

Miklos, can you check out next and see if your problem case is handled?

I just checked next and right, that solves the problem I was fixing.

So -- sorry for the noise. :-)

Don't be sorry.

People noticing an issue, trying 'master' and 'next' to see that it has already been resolved, is the only way for us to know we are helping people other than those who had the original itch.

The ideal would be for more people to run 'next' and report both problems and successes ;-)