git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Robert Dailey <rcdailey.lists@gmail.com>
To: Git <git@vger.kernel.org>
Subject: Re: Conditional newline in pretty format
Date: Tue, 17 Mar 2020 10:37:13 -0500	[thread overview]
Message-ID: <CAHd499B+ro+d0bGA+-Y1Qnfkc1vMzXCnBfZmtZv+CscUXim=wQ@mail.gmail.com> (raw)
In-Reply-To: <CAHd499DiCi3FJb9qWJNBNKyVQg_zYMgJRuYcH_pOP3LnGwk5Tg@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 1667 bytes --]

On Tue, Mar 17, 2020 at 10:28 AM Robert Dailey <rcdailey.lists@gmail.com> wrote:
>
> 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.

[-- Attachment #2: alias2.png --]
[-- Type: image/png, Size: 14317 bytes --]

[-- Attachment #3: alias1.png --]
[-- Type: image/png, Size: 18423 bytes --]

  reply	other threads:[~2020-03-17 15:37 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-17 15:28 Conditional newline in pretty format Robert Dailey
2020-03-17 15:37 ` Robert Dailey [this message]
2020-03-17 17:18   ` Jeff King
2020-03-17 17:27     ` Robert Dailey
2020-03-17 17:55       ` 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

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAHd499B+ro+d0bGA+-Y1Qnfkc1vMzXCnBfZmtZv+CscUXim=wQ@mail.gmail.com' \
    --to=rcdailey.lists@gmail.com \
    --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.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).