public inbox for git@vger.kernel.org 
 help / color / mirror / Atom feed
* [Bug] commit cleanup does not happen during autosquash rebase
@ 2025-08-13 11:39 Simon Cheng
  2025-08-18 15:14 ` Phillip Wood
  0 siblings, 1 reply; 4+ messages in thread
From: Simon Cheng @ 2025-08-13 11:39 UTC (permalink / raw)
  To: git

Thank you for filling out a Git bug report!
Please answer the following questions to help us understand your issue.

What did you do before the bug happened? (Steps to reproduce your issue)

1. Initialize a git repo with `git init`
2. Install a custom `prepare-commit-msg` hook that injects some comments
  - Intention: inject the output of `git log --oneline -n10` during
interactive commit, so I can see past commits
3. Run `git config commit.cleanup strip`
  - Intention: strip the injected comments too in non-interactive mode
(e.g. `git cherry-pick` & `git rebase`)
4. Run `touch foo && git add -A && git commit -m "Initial commit"`
5. Run `touch bar && git add -A && git commit --fixup=@`
6. Run `git rebase --root --autosquash`

What did you expect to happen? (Expected behavior)

Git would perform the autosquash, while keeping the commit message of
the squash target unchanged.

What happened instead? (Actual behavior)

Git performed the autosquash, but the commit message of the squash
target is now clobbered with my injected comments.

What's different between what you expected and what actually happened?

I expected commit cleanup to happen during the autosquash. It seems
like that didn't happen.

Anything else you want to add:

Here is my `prepare-commit-msg` script. But I expect this issue to be
replicable with anything that injects comments.

```
#!/usr/bin/env bash
{
  echo '# Last 10 commits:'
  git log --oneline -n 10 --decorate=short | sed 's/^/#   /'
  echo '#'
} >> "$1"
```

Please review the rest of the bug report below.
You can delete any lines you don't wish to share.


[System Info]
git version:
git version 2.50.1
cpu: x86_64
built from commit: d82adb61ba2fd11d8f2587fca1b6bd7925ce4044
sizeof-long: 8
sizeof-size_t: 8
shell-path: /bin/sh
libcurl: 8.14.1
OpenSSL: OpenSSL 3.5.1 1 Jul 2025
zlib-ng: 2.2.4
SHA-1: SHA1_DC
SHA-256: SHA256_BLK
uname: Linux 6.12.41-1-lts #1 SMP PREEMPT_DYNAMIC Fri, 01 Aug 2025
20:42:03 +0000 x86_64
compiler info: gnuc: 15.1
libc info: glibc: 2.42
$SHELL (typically, interactive shell): /bin/bash


[Enabled Hooks]
prepare-commit-msg

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Bug] commit cleanup does not happen during autosquash rebase
  2025-08-13 11:39 [Bug] commit cleanup does not happen during autosquash rebase Simon Cheng
@ 2025-08-18 15:14 ` Phillip Wood
  2025-09-15  9:03   ` Simon Cheng
  0 siblings, 1 reply; 4+ messages in thread
From: Phillip Wood @ 2025-08-18 15:14 UTC (permalink / raw)
  To: Simon Cheng, git; +Cc: Johannes Schindelin

Hi Simon

On 13/08/2025 12:39, Simon Cheng wrote:
> 
> What did you do before the bug happened? (Steps to reproduce your issue)
> 
> 1. Initialize a git repo with `git init`
> 2. Install a custom `prepare-commit-msg` hook that injects some comments
>    - Intention: inject the output of `git log --oneline -n10` during
> interactive commit, so I can see past commits
> 3. Run `git config commit.cleanup strip`
>    - Intention: strip the injected comments too in non-interactive mode
> (e.g. `git cherry-pick` & `git rebase`)
> 4. Run `touch foo && git add -A && git commit -m "Initial commit"`
> 5. Run `touch bar && git add -A && git commit --fixup=@`
> 6. Run `git rebase --root --autosquash`

Thanks for providing a simple way to reproduce this

> What did you expect to happen? (Expected behavior)
> 
> Git would perform the autosquash, while keeping the commit message of
> the squash target unchanged.
> 
> What happened instead? (Actual behavior)
> 
> Git performed the autosquash, but the commit message of the squash
> target is now clobbered with my injected comments.

It looks like this stems from f7d42ceec52 (rebase -i: do leave commit 
message intact in fixup! chains, 2021-01-28) which was added in response 
to a bug report[1]. That commit switched from always cleaning up the 
fixup message to never cleaning it up. I wonder if instead we should be 
respecting the user's commit.cleanup setting. The commit message says 
that should not respect commit.cleanup because we want to use the 
message verbatim but that is not what we do with "pick" commands which 
respect commit.cleanup if it is set. Given that we call the 
prepare-commit-msg hook we cannot be sure that we're reusing the 
original commit message verbatim anyway so I think we should probably 
change "fixup" commands to use the same cleanup flags as "pick" commands.

I'm going to be off the list for a week from tomorrow but I'll try and 
look at this again when I'm back if no one else has picked it up in the 
meantime.

Thanks

Phillip

[1] 
https://lore.kernel.org/git/CANVGpwZGbzYLMeMze64e_OU9p3bjyEgzC5thmNBr6LttBt+YGw@mail.gmail.com/

> What's different between what you expected and what actually happened?
> 
> I expected commit cleanup to happen during the autosquash. It seems
> like that didn't happen.
> 
> Anything else you want to add:
> 
> Here is my `prepare-commit-msg` script. But I expect this issue to be
> replicable with anything that injects comments.
> 
> ```
> #!/usr/bin/env bash
> {
>    echo '# Last 10 commits:'
>    git log --oneline -n 10 --decorate=short | sed 's/^/#   /'
>    echo '#'
> } >> "$1"
> ```
> 
> Please review the rest of the bug report below.
> You can delete any lines you don't wish to share.
> 
> 
> [System Info]
> git version:
> git version 2.50.1
> cpu: x86_64
> built from commit: d82adb61ba2fd11d8f2587fca1b6bd7925ce4044
> sizeof-long: 8
> sizeof-size_t: 8
> shell-path: /bin/sh
> libcurl: 8.14.1
> OpenSSL: OpenSSL 3.5.1 1 Jul 2025
> zlib-ng: 2.2.4
> SHA-1: SHA1_DC
> SHA-256: SHA256_BLK
> uname: Linux 6.12.41-1-lts #1 SMP PREEMPT_DYNAMIC Fri, 01 Aug 2025
> 20:42:03 +0000 x86_64
> compiler info: gnuc: 15.1
> libc info: glibc: 2.42
> $SHELL (typically, interactive shell): /bin/bash
> 
> 
> [Enabled Hooks]
> prepare-commit-msg
> 


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Bug] commit cleanup does not happen during autosquash rebase
  2025-08-18 15:14 ` Phillip Wood
@ 2025-09-15  9:03   ` Simon Cheng
  2025-09-18 15:12     ` Phillip Wood
  0 siblings, 1 reply; 4+ messages in thread
From: Simon Cheng @ 2025-09-15  9:03 UTC (permalink / raw)
  To: phillip.wood; +Cc: git, Johannes Schindelin

Resending because I accidentally used HTML mode.

Thanks Phillip,

Sorry for replying so late. I forgot to set up notifications for this
email address, so I had basically completely forgotten about this
matter.

Yes I fully agree with your proposed approach. Also it's probably a
good idea to update the `git-config(1)` man page to document all the
commands affected by `commit.cleanup`.

Cheers,

Simon


On Mon, 18 Aug 2025 at 23:14, Phillip Wood <phillip.wood123@gmail•com> wrote:
>
> Hi Simon
>
> On 13/08/2025 12:39, Simon Cheng wrote:
> >
> > What did you do before the bug happened? (Steps to reproduce your issue)
> >
> > 1. Initialize a git repo with `git init`
> > 2. Install a custom `prepare-commit-msg` hook that injects some comments
> >    - Intention: inject the output of `git log --oneline -n10` during
> > interactive commit, so I can see past commits
> > 3. Run `git config commit.cleanup strip`
> >    - Intention: strip the injected comments too in non-interactive mode
> > (e.g. `git cherry-pick` & `git rebase`)
> > 4. Run `touch foo && git add -A && git commit -m "Initial commit"`
> > 5. Run `touch bar && git add -A && git commit --fixup=@`
> > 6. Run `git rebase --root --autosquash`
>
> Thanks for providing a simple way to reproduce this
>
> > What did you expect to happen? (Expected behavior)
> >
> > Git would perform the autosquash, while keeping the commit message of
> > the squash target unchanged.
> >
> > What happened instead? (Actual behavior)
> >
> > Git performed the autosquash, but the commit message of the squash
> > target is now clobbered with my injected comments.
>
> It looks like this stems from f7d42ceec52 (rebase -i: do leave commit
> message intact in fixup! chains, 2021-01-28) which was added in response
> to a bug report[1]. That commit switched from always cleaning up the
> fixup message to never cleaning it up. I wonder if instead we should be
> respecting the user's commit.cleanup setting. The commit message says
> that should not respect commit.cleanup because we want to use the
> message verbatim but that is not what we do with "pick" commands which
> respect commit.cleanup if it is set. Given that we call the
> prepare-commit-msg hook we cannot be sure that we're reusing the
> original commit message verbatim anyway so I think we should probably
> change "fixup" commands to use the same cleanup flags as "pick" commands.
>
> I'm going to be off the list for a week from tomorrow but I'll try and
> look at this again when I'm back if no one else has picked it up in the
> meantime.
>
> Thanks
>
> Phillip
>
> [1]
> https://lore.kernel.org/git/CANVGpwZGbzYLMeMze64e_OU9p3bjyEgzC5thmNBr6LttBt+YGw@mail.gmail.com/
>
> > What's different between what you expected and what actually happened?
> >
> > I expected commit cleanup to happen during the autosquash. It seems
> > like that didn't happen.
> >
> > Anything else you want to add:
> >
> > Here is my `prepare-commit-msg` script. But I expect this issue to be
> > replicable with anything that injects comments.
> >
> > ```
> > #!/usr/bin/env bash
> > {
> >    echo '# Last 10 commits:'
> >    git log --oneline -n 10 --decorate=short | sed 's/^/#   /'
> >    echo '#'
> > } >> "$1"
> > ```
> >
> > Please review the rest of the bug report below.
> > You can delete any lines you don't wish to share.
> >
> >
> > [System Info]
> > git version:
> > git version 2.50.1
> > cpu: x86_64
> > built from commit: d82adb61ba2fd11d8f2587fca1b6bd7925ce4044
> > sizeof-long: 8
> > sizeof-size_t: 8
> > shell-path: /bin/sh
> > libcurl: 8.14.1
> > OpenSSL: OpenSSL 3.5.1 1 Jul 2025
> > zlib-ng: 2.2.4
> > SHA-1: SHA1_DC
> > SHA-256: SHA256_BLK
> > uname: Linux 6.12.41-1-lts #1 SMP PREEMPT_DYNAMIC Fri, 01 Aug 2025
> > 20:42:03 +0000 x86_64
> > compiler info: gnuc: 15.1
> > libc info: glibc: 2.42
> > $SHELL (typically, interactive shell): /bin/bash
> >
> >
> > [Enabled Hooks]
> > prepare-commit-msg
> >
>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Bug] commit cleanup does not happen during autosquash rebase
  2025-09-15  9:03   ` Simon Cheng
@ 2025-09-18 15:12     ` Phillip Wood
  0 siblings, 0 replies; 4+ messages in thread
From: Phillip Wood @ 2025-09-18 15:12 UTC (permalink / raw)
  To: Simon Cheng, phillip.wood; +Cc: git, Johannes Schindelin

On 15/09/2025 10:03, Simon Cheng wrote:
> Resending because I accidentally used HTML mode.
> 
> Thanks Phillip,
> 
> Sorry for replying so late. I forgot to set up notifications for this
> email address, so I had basically completely forgotten about this
> matter.

You're reply turned out to be timely as I was thinking about this bug 
just before I read it on Monday. I've sent a patch which you should be 
Cc'd on. For anyone following the discussion on the list it is available 
at 
https://lore.kernel.org/git/cover.1758186038.git.phillip.wood@dunelm.org.uk/

> Yes I fully agree with your proposed approach. Also it's probably a
> good idea to update the `git-config(1)` man page to document all the
> commands affected by `commit.cleanup`.

That's a good idea but it will mean a little bit of work to audit how 
commands are affected by that config setting.

Thanks

Phillip

> Cheers,
> 
> Simon
> 
> 
> On Mon, 18 Aug 2025 at 23:14, Phillip Wood <phillip.wood123@gmail•com> wrote:
>>
>> Hi Simon
>>
>> On 13/08/2025 12:39, Simon Cheng wrote:
>>>
>>> What did you do before the bug happened? (Steps to reproduce your issue)
>>>
>>> 1. Initialize a git repo with `git init`
>>> 2. Install a custom `prepare-commit-msg` hook that injects some comments
>>>     - Intention: inject the output of `git log --oneline -n10` during
>>> interactive commit, so I can see past commits
>>> 3. Run `git config commit.cleanup strip`
>>>     - Intention: strip the injected comments too in non-interactive mode
>>> (e.g. `git cherry-pick` & `git rebase`)
>>> 4. Run `touch foo && git add -A && git commit -m "Initial commit"`
>>> 5. Run `touch bar && git add -A && git commit --fixup=@`
>>> 6. Run `git rebase --root --autosquash`
>>
>> Thanks for providing a simple way to reproduce this
>>
>>> What did you expect to happen? (Expected behavior)
>>>
>>> Git would perform the autosquash, while keeping the commit message of
>>> the squash target unchanged.
>>>
>>> What happened instead? (Actual behavior)
>>>
>>> Git performed the autosquash, but the commit message of the squash
>>> target is now clobbered with my injected comments.
>>
>> It looks like this stems from f7d42ceec52 (rebase -i: do leave commit
>> message intact in fixup! chains, 2021-01-28) which was added in response
>> to a bug report[1]. That commit switched from always cleaning up the
>> fixup message to never cleaning it up. I wonder if instead we should be
>> respecting the user's commit.cleanup setting. The commit message says
>> that should not respect commit.cleanup because we want to use the
>> message verbatim but that is not what we do with "pick" commands which
>> respect commit.cleanup if it is set. Given that we call the
>> prepare-commit-msg hook we cannot be sure that we're reusing the
>> original commit message verbatim anyway so I think we should probably
>> change "fixup" commands to use the same cleanup flags as "pick" commands.
>>
>> I'm going to be off the list for a week from tomorrow but I'll try and
>> look at this again when I'm back if no one else has picked it up in the
>> meantime.
>>
>> Thanks
>>
>> Phillip
>>
>> [1]
>> https://lore.kernel.org/git/CANVGpwZGbzYLMeMze64e_OU9p3bjyEgzC5thmNBr6LttBt+YGw@mail.gmail.com/
>>
>>> What's different between what you expected and what actually happened?
>>>
>>> I expected commit cleanup to happen during the autosquash. It seems
>>> like that didn't happen.
>>>
>>> Anything else you want to add:
>>>
>>> Here is my `prepare-commit-msg` script. But I expect this issue to be
>>> replicable with anything that injects comments.
>>>
>>> ```
>>> #!/usr/bin/env bash
>>> {
>>>     echo '# Last 10 commits:'
>>>     git log --oneline -n 10 --decorate=short | sed 's/^/#   /'
>>>     echo '#'
>>> } >> "$1"
>>> ```
>>>
>>> Please review the rest of the bug report below.
>>> You can delete any lines you don't wish to share.
>>>
>>>
>>> [System Info]
>>> git version:
>>> git version 2.50.1
>>> cpu: x86_64
>>> built from commit: d82adb61ba2fd11d8f2587fca1b6bd7925ce4044
>>> sizeof-long: 8
>>> sizeof-size_t: 8
>>> shell-path: /bin/sh
>>> libcurl: 8.14.1
>>> OpenSSL: OpenSSL 3.5.1 1 Jul 2025
>>> zlib-ng: 2.2.4
>>> SHA-1: SHA1_DC
>>> SHA-256: SHA256_BLK
>>> uname: Linux 6.12.41-1-lts #1 SMP PREEMPT_DYNAMIC Fri, 01 Aug 2025
>>> 20:42:03 +0000 x86_64
>>> compiler info: gnuc: 15.1
>>> libc info: glibc: 2.42
>>> $SHELL (typically, interactive shell): /bin/bash
>>>
>>>
>>> [Enabled Hooks]
>>> prepare-commit-msg
>>>
>>


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2025-09-18 15:12 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-13 11:39 [Bug] commit cleanup does not happen during autosquash rebase Simon Cheng
2025-08-18 15:14 ` Phillip Wood
2025-09-15  9:03   ` Simon Cheng
2025-09-18 15:12     ` Phillip Wood

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox