#1092856 /usr/bin/git: sample hook signed-off-by code corrupts commits without final newline

Package:
git
Source:
git
Description:
fast, scalable, distributed revision control system
Submitter:
Ian Jackson
Date:
2025-02-18 01:48:01 UTC
Severity:
normal
Tags:
#1092856#5
Date:
2025-01-12 11:53:48 UTC
From:
To:
To reproduce:

  git clone https://salsa.debian.org/dgit-team/dgit.git -b commit-message-sob-botch-repro
  cd dgit/
  cp .git/hooks/prepare-commit-msg{.sample,}
  # (The following enables the SOB-processing parts of the sample:)
  perl -i~ -pe 's{^\# }{} if m{^\# SOB}..m{^$}' .git/hooks/prepare-commit-msg
  git-rebase -i HEAD~5

  # Now, delete the first commit from the interactive rebase instructions,
  # to force an actual rewrite of the final commit.
  # Complete the rebase.

  git cat-file commit HEAD

Actual results:

  tree 79d4e0670895c30744706c5f835268e36dc8c99a
  parent ...

  tag2upload-oracled: Coding style changes
  Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>

Expected results:

  tree 79d4e0670895c30744706c5f835268e36dc8c99a
  parent ...

  tag2upload-oracled: Coding style changes

  Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>

Discussion:

It is unfortunate that this is done by ad-hoc open-coding in a script
that git promiscuously copies everywhere and that you're expected to
edit.

IMO the correct answer is: provide the same code as a small program,
and call that program (commented out) from the sample hook.
Users who enable the hook will then get future updates.

Commits without final newline are generated by the gitlab web UI when
one uses the "apply suggested changes" functionality.

Thanks for your attention,
Ian.

#1092856#10
Date:
2025-02-18 01:37:25 UTC
From:
To:
I believe that someone has sent a patch to the Git list to fix this
problem (c02414a997 ("interpret-trailers: handle message without
trailing newline", 2024-09-06)) and it's included in 2.46.2.  I'm
unable to reproduce it with 2.48.

The good news is that this is fixed in `git interpret-trailers` so
even older versions of the hooks should continue to work.

I will think about this and maybe try to start a discussion upstream.
I think the goal of the sample hooks is to show what you _could_ do and
instruct you on how to use the hooks and not to be actually generally
useful, but I admit that we may have been too successful with our
examples and people may have ended up actually using them.

#1092856#15
Date:
2025-02-18 01:37:25 UTC
From:
To:
I believe that someone has sent a patch to the Git list to fix this
problem (c02414a997 ("interpret-trailers: handle message without
trailing newline", 2024-09-06)) and it's included in 2.46.2.  I'm
unable to reproduce it with 2.48.

The good news is that this is fixed in `git interpret-trailers` so
even older versions of the hooks should continue to work.

I will think about this and maybe try to start a discussion upstream.
I think the goal of the sample hooks is to show what you _could_ do and
instruct you on how to use the hooks and not to be actually generally
useful, but I admit that we may have been too successful with our
examples and people may have ended up actually using them.