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

Re: `cherry-pick -x' and git-interpret-trailers

From
KHKristoffer Haugsbakk <kristofferhaugsbakk@fastmail.com>
Date
Oct 28, 2024, 21:18 UTC
Message-ID
<c6f58024-45f5-4012-87a4-6b86ab2cd31b@app.fastmail.com>
In-Reply-To
<ab71a27d-728e-425a-8729-8699c9369bca@app.fastmail.com>
On Mon, Oct 28, 2024, at 19:43, Nicholas Sielicki wrote:
Show 12 quoted lines
> If one uses `git cherry-pick -x' to apply a commit to a stable branch
> from elsewhere, git appends something like:
>
>> Tested-by: Some Teammate <some.teammate@somedomain.com>
>> Signed-off-by: Some User <some.user@somedomain.com>
>> (cherry picked from commit 2efe13923d0ff714b1b0f3b7175e714f0e295727) <--- this
>
> IMO this is inconsistent in two ways:
>
> 1. it's unclear to me why the cherry-pick metadata isn't emitted in
> trailer form, ie: `Cherry-Picked-From-Commit: <...>', making it work
> with `git-interpret-trailers'.

I agree that would be better. Modulo history and backwards compatibility concerns.

> 2. I'm not sure if any tooling (external or otherwise) breaks because
> of this, but the existing trailers now have non-trailer content
> following them, so it's ambiguous whether they still qualify as
> trailers at first glance. (possibly, this is intentional?)
They still qualify.  See git-interpret-trailers(1)
  “ Existing trailers are extracted from the input by looking for a
    group of one or more lines that (i) is all trailers, or (ii)
    contains at least one Git-generated or user-configured trailer and
    consists of at least 25% trailers.

That example would work even if you only had one existing trailer (50% at the end).

I don’t know what the significance of “user-configured” is here. I deleted all my configuration and tested with something made up and `git interpret-trailers --parse`. Those novel-looking trailers still got output as trailers when placed before a cherry-pick line.

Show 5 quoted lines
> Realistically, the only thing worse than this^ would be to have a
> mixture of two formats in the same repository, which is to say,
> without a surefire way to to share repository config defaults, I can't
> imagine there's a backwards-compatible solution to changing the `-x'
> default behavior and git is stuck with it.
Make a new option?  Like `--trailer`?
> It could be possible to extend the existing behavior with git-notes?
> Added benefit of that would be that you could mark both commits
> involved with `Cherry-Picked-By' and `Cherry-Picked-From'.
Why Notes?  A trailer (a proper one) seems more straightforward.
There was a “crossreference” patch series from 2018:
https://lore.kernel.org/git/20181211234909.2855638-1-tj@kernel.org/
❦
You could emulate something like `git cherry-pick --trailer`:

``` #!/bin/sh # arg 1: commit set -u $ git config trailer.cherry.key Cherry-picked-from $ cat script #!/bin/sh

git showref "$1"
$ git config trailer.cherry.cmd ./script
$ git cherry-pick "$1" &&
$ git commit --trailer="cherry: $1" \
    --amend --no-edit
```
Previous: Nicholas Sielicki
Message 2 of 2 in “`cherry-pick -x' and git-interpret-trailers”
  1. Nicholas SielickiOct 28, 2024
  2. Kristoffer HaugsbakkOct 28, 2024

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.