git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: Conditional newline in pretty format

From
RDRobert Dailey <rcdailey.lists@gmail.com>
Date
Mar 17, 2020, 15:37 UTC
Message-ID
<CAHd499B+ro+d0bGA+-Y1Qnfkc1vMzXCnBfZmtZv+CscUXim=wQ@mail.gmail.com>
In-Reply-To
<CAHd499DiCi3FJb9qWJNBNKyVQg_zYMgJRuYcH_pOP3LnGwk5Tg@mail.gmail.com>
On Tue, Mar 17, 2020 at 10:28 AM Robert Dailey <rcdailey.lists@gmail.com> wrote:
Show 20 quoted lines
>
> I have the following alias:
>
> ```
> [alias]
>     release-notes = log --no-merges --pretty=format:'* %s%n%n%w(100,2,2)%b'
> ```
>
> With a branch `topic` checked out, I run it like so:
>
>     $ git release-notes origin..
>
> This gives me the "release notes" on my branch. The goal is to have it
> formatted as a bullet-point list in markdown format so I can just copy
> & paste this output into Github, Bitbucket, or other sites and have it
> already set up for render correctly.
>
> It works perfectly right now except for the case where `%b` is empty.
> In that case, I just want one newline after `%s` instead of 2. Is
> there a way to make my second `%n` conditional on `%b` having a value?

Apologies, I forgot to add a lot more detail. First, I have two attachments. The first one, `alias1.png`, shows what log output looks like when I execute the command mentioned above. The red annotation box in the image points out the superfluous newlines in the entry that has no log body (only subject). This is the newline I'm trying to get rid of.

Another solution I tried is `%+b`, based on this documentation:
> If you add a + (plus sign) after '%' of a placeholder, a line-feed is inserted
> immediately before the expansion if and only if the placeholder expands
> to a non-empty string.

However, the output I get is not as expected. Instead of a newline character, it appears to just insert a single space character. Observe the result in attachment named `alias2.png`. I'm not sure if this is a bug or if I'm just doing it wrong. Again, any help is greatly appreciated.

Previous: Robert DaileyNext: Jeff King
Message 2 of 5 in “Conditional newline in pretty format”
  1. Robert DaileyMar 17, 2020
  2. Robert DaileyMar 17, 2020
  3. Jeff KingMar 17, 2020
  4. Robert DaileyMar 17, 2020
  5. Jeff KingMar 17, 2020

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.