# [PATCH] cherry-pick -x: improve handling of one-liner commit messages

5 messages from 2013-03-29 to 2013-03-29. Participants: Miklos Vajna, Junio C Hamano, Brandon Casey.
Thread: https://gitlist.dev/t/33326

## Miklos Vajna, 2013-03-29 15:38

Subject: [PATCH] cherry-pick -x: improve handling of one-liner commit messages
Message-ID: <20130329153818.GB27251@suse.cz>
URL: https://gitlist.dev/e/20130329153818.GB27251%40suse.cz

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

```

## Junio C Hamano, 2013-03-29 17:23

Subject: Re: [PATCH] cherry-pick -x: improve handling of one-liner commit messages
Message-ID: <7v8v56p1bl.fsf@alter.siamese.dyndns.org>
URL: https://gitlist.dev/e/7v8v56p1bl.fsf%40alter.siamese.dyndns.org
In-Reply-To: <20130329153818.GB27251@suse.cz>

```
Miklos Vajna <vmiklos@suse.cz> writes:

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

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

```

## Brandon Casey, 2013-03-29 17:41

Subject: Re: [PATCH] cherry-pick -x: improve handling of one-liner commit messages
Message-ID: <CA+sFfMet0578rLwAKBBsd8DM3thsw=8+joEAAf44TzwqUZgXzw@mail.gmail.com>
URL: https://gitlist.dev/e/CA%2BsFfMet0578rLwAKBBsd8DM3thsw%3D8%2BjoEAAf44TzwqUZgXzw%40mail.gmail.com
In-Reply-To: <7v8v56p1bl.fsf@alter.siamese.dyndns.org>

```
On Fri, Mar 29, 2013 at 10:23 AM, Junio C Hamano <gitster@pobox.com> wrote:
> Miklos Vajna <vmiklos@suse.cz> writes:
>
>> 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?

Yeah, I think this case is already handled.

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

-Brandon

```

## Miklos Vajna, 2013-03-29 20:39

Subject: Re: [PATCH] cherry-pick -x: improve handling of one-liner commit messages
Message-ID: <20130329203915.GA5157@suse.cz>
URL: https://gitlist.dev/e/20130329203915.GA5157%40suse.cz
In-Reply-To: <CA+sFfMet0578rLwAKBBsd8DM3thsw=8+joEAAf44TzwqUZgXzw@mail.gmail.com>

```
Hi,

On Fri, Mar 29, 2013 at 10:41:17AM -0700, Brandon Casey <drafnel@gmail.com> wrote:
> > Sign-off?

Indeed, I forgot about it, my bad.

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

```

## Junio C Hamano, 2013-03-29 20:49

Subject: Re: [PATCH] cherry-pick -x: improve handling of one-liner commit messages
Message-ID: <7vr4iylyna.fsf@alter.siamese.dyndns.org>
URL: https://gitlist.dev/e/7vr4iylyna.fsf%40alter.siamese.dyndns.org
In-Reply-To: <20130329203915.GA5157@suse.cz>

```
Miklos Vajna <vmiklos@suse.cz> writes:

> On Fri, Mar 29, 2013 at 10:41:17AM -0700, Brandon Casey <drafnel@gmail.com> wrote:
>
>> > 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. :-)

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 ;-)

```
