# Bug: "git log --format='format:%+s%+b'" doesn't insert newline before body

7 messages from 2016-07-24 to 2016-07-25. Participants: Ilya Tumaykin, Beat Bolli, Johannes Schindelin, Jakub Narębski.
Thread: https://gitlist.dev/t/42914

## Ilya Tumaykin, 2016-07-24 13:46

Subject: Bug: "git log --format='format:%+s%+b'" doesn't insert newline before body
Message-ID: <8915446.47C9zkNvuX@photon>
URL: https://gitlist.dev/e/8915446.47C9zkNvuX%40photon

```
Hello.

Steps to reproduce:
$ git init
$ >123
$ git add 123
$ git commit -v -m 'This is subject' -m 'And this is body'
$ git --no-pager log -1 --format='format:%+s%+b'

Actual results:
ˋˋˋ

This is subject
And this is body
ˋˋˋ

Expected results:
ˋˋˋ

This is subject

And this is body
ˋˋˋ

$ git --version
git version 2.9.2

Please fix.

-- 
Best regards.
Ilya Tumaykin.

```

## Beat Bolli, 2016-07-25 06:55

Subject: Re: Bug:
Message-ID: <loom.20160725T085326-574@post.gmane.org>
URL: https://gitlist.dev/e/loom.20160725T085326-574%40post.gmane.org
In-Reply-To: <8915446.47C9zkNvuX@photon>

```
Ilya Tumaykin <itumaykin <at> gmail.com> writes:

> $ git --no-pager log -1 --format='format:%+s%+b'
> Please fix.

Simply use `git --no-pager log -1 --format='format:%+s%n%+b'`

The message body excludes the empty line preceding it.






```

## Johannes Schindelin, 2016-07-25 07:33

Subject: Re: Bug: "git log --format='format:%+s%+b'" doesn't insert newline before body
Message-ID: <alpine.DEB.2.20.1607250926320.14111@virtualbox>
URL: https://gitlist.dev/e/alpine.DEB.2.20.1607250926320.14111%40virtualbox
In-Reply-To: <8915446.47C9zkNvuX@photon>

```
Hi Ilya,

On Sun, 24 Jul 2016, Ilya Tumaykin wrote:

> Steps to reproduce:
> $ git init
> $ >123
> $ git add 123
> $ git commit -v -m 'This is subject' -m 'And this is body'
> $ git --no-pager log -1 --format='format:%+s%+b'
> 
> Actual results:
> ˋˋˋ
> 
> This is subject
> And this is body
> ˋˋˋ
> 
> Expected results:
> ˋˋˋ
> 
> This is subject
> 
> And this is body
> ˋˋˋ

The empty line between commit subject and body is neither part of the
subject nor of the body. That means that the above-mentioned expectation
was incorrect.

Unless you somehow allow empty commit messages (Git does not, unless you
play games with low-level commands), the second '+' is unnecessarily
conditional. Therefore "%s%n%+b" *might* do what you intended (I would not
know, because that information was missing from the report).

Ciao,
Johannes

```

## Ilya Tumaykin, 2016-07-25 07:51

Subject: Re: Bug: "git log --format='format:%+s%+b'" doesn't insert newline before body
Message-ID: <1693749.WYZjdcdZj5@photon>
URL: https://gitlist.dev/e/1693749.WYZjdcdZj5%40photon
In-Reply-To: <alpine.DEB.2.20.1607250926320.14111@virtualbox>

```
On Monday 25 July 2016 09:33:00 Johannes Schindelin wrote:
> Hi Ilya,
> 
> On Sun, 24 Jul 2016, Ilya Tumaykin wrote:
> > Steps to reproduce:
> > $ git init
> > $ >123
> > $ git add 123
> > $ git commit -v -m 'This is subject' -m 'And this is body'
> > $ git --no-pager log -1 --format='format:%+s%+b'
> > 
> > Actual results:
> > ˋˋˋ
> > 
> > This is subject
> > And this is body
> > ˋˋˋ
> > 
> > Expected results:
> > ˋˋˋ
> > 
> > This is subject
> > 
> > And this is body
> > ˋˋˋ
> 
> The empty line between commit subject and body is neither part of the
> subject nor of the body. That means that the above-mentioned expectation
> was incorrect.

According to 'git-log' man page '%+b' should insert linefeed "immediately 
before the expansion if and only if the placeholder expands to a non-empty 
string." Here "%b" expands to a non-empty string, thus I expect a linefeed 
before it. Or am I misinterpreting man page somehow?

> Unless you somehow allow empty commit messages (Git does not, unless you
> play games with low-level commands), the second '+' is unnecessarily
> conditional. Therefore "%s%n%+b" *might* do what you intended (I would not
> know, because that information was missing from the report).

I want to display '%B', but add colours to '%s'. Thus I have to separately 
include '%s' and '%b', and not just '%B'. I was using '%+s%n%+b' with extra 
colour formatting as a workaround for some time now.

> Ciao,
> Johannes

-- 
Best regards.
Ilya Tumaykin.

```

## Johannes Schindelin, 2016-07-25 08:06

Subject: Re: Bug: "git log --format='format:%+s%+b'" doesn't insert newline before body
Message-ID: <alpine.DEB.2.20.1607251003360.14111@virtualbox>
URL: https://gitlist.dev/e/alpine.DEB.2.20.1607251003360.14111%40virtualbox
In-Reply-To: <1693749.WYZjdcdZj5@photon>

```
Hi Ilya,

On Mon, 25 Jul 2016, Ilya Tumaykin wrote:

> On Monday 25 July 2016 09:33:00 Johannes Schindelin wrote:
> > 
> > On Sun, 24 Jul 2016, Ilya Tumaykin wrote:
> > [...]
> > > $ git --no-pager log -1 --format='format:%+s%+b'
> > > 
> > > Actual results:
> > > ˋˋˋ
> > > 
> > > This is subject
> > > And this is body
> > > ˋˋˋ
> 
> According to 'git-log' man page '%+b' should insert linefeed "immediately 
> before the expansion if and only if the placeholder expands to a non-empty 
> string." Here "%b" expands to a non-empty string, thus I expect a linefeed 
> before it. Or am I misinterpreting man page somehow?

The line break is there: after the subject. The misinterpretation is most
likely the assumption that the new-line "character" is part of the commit
subject; It is not.

> > Unless you somehow allow empty commit messages (Git does not, unless
> > you play games with low-level commands), the second '+' is
> > unnecessarily conditional. Therefore "%s%n%+b" *might* do what you
> > intended (I would not know, because that information was missing from
> > the report).
> 
> I want to display '%B', but add colours to '%s'. Thus I have to
> separately include '%s' and '%b', and not just '%B'. I was using
> '%+s%n%+b' with extra colour formatting as a workaround for some time
> now.

Okay. Hopefully the explanation above clarifies that this is not a
work-around, but the correct solution.

Ciao,
Johannes

```

## Ilya Tumaykin, 2016-07-25 10:49

Subject: Re: Bug: "git log --format='format:%+s%+b'" doesn't insert newline before body
Message-ID: <2082892.BZVOcV7i8n@photon>
URL: https://gitlist.dev/e/2082892.BZVOcV7i8n%40photon
In-Reply-To: <alpine.DEB.2.20.1607251003360.14111@virtualbox>

```
On Monday 25 July 2016 10:06:28 Johannes Schindelin wrote:
> Hi Ilya,
> 
> On Mon, 25 Jul 2016, Ilya Tumaykin wrote:
> > On Monday 25 July 2016 09:33:00 Johannes Schindelin wrote:
> > > On Sun, 24 Jul 2016, Ilya Tumaykin wrote:
> > > [...]
> > > 
> > > > $ git --no-pager log -1 --format='format:%+s%+b'
> > > > 
> > > > Actual results:
> > > > ˋˋˋ
> > > > 
> > > > This is subject
> > > > And this is body
> > > > ˋˋˋ
> > 
> > According to 'git-log' man page '%+b' should insert linefeed "immediately
> > before the expansion if and only if the placeholder expands to a non-empty
> > string." Here "%b" expands to a non-empty string, thus I expect a linefeed
> > before it. Or am I misinterpreting man page somehow?
> 
> The line break is there: after the subject. The misinterpretation is most
> likely the assumption that the new-line "character" is part of the commit
> subject; It is not.

I see. Thank you very much for the explanation. This does help me.

-- 
Best regards.
Ilya Tumaykin.

```

## Jakub Narębski, 2016-07-25 17:28

Subject: Re: Bug: "git log --format='format:%+s%+b'" doesn't insert newline before body
Message-ID: <57964C29.9000902@gmail.com>
URL: https://gitlist.dev/e/57964C29.9000902%40gmail.com
In-Reply-To: <alpine.DEB.2.20.1607250926320.14111@virtualbox>

```
W dniu 2016-07-25 o 09:33, Johannes Schindelin pisze:

> Therefore "%s%n%+b" *might* do what you intended (I would not
> know, because that information was missing from the report).

Shouldn't it be "%s%n%n%-b" or "%s%n%-b"?

-- 
Jakub Narębski

```
