git-fixup icon indicating copy to clipboard operation
git-fixup copied to clipboard

Respect pre-commit hooks

Open mgehre-amd opened this issue 1 year ago • 1 comments

This is a great tool that I had waiting to have for last couple of years. Thanks!

What I currently see is the following:

  1. I make a change with a formatting error
  2. I do git add -p to stage it
  3. I do git fixup to fix it up
  4. git fixup tries to create a commit, but that fails due to my pre-commit hooks
  5. git fixup still calls interactive rebase, which now shows an editor with the rebase instructions; but there is no fixup commit here
  6. I save the interactive rebase editor, the no-op rebase happens, and I'm back. I now go and commit the formatting corrections.

It would be great if git-fixup would stop at 4. if the pre-commit hooks fail, and doesn't run the interactive rebase anyways.

mgehre-amd avatar Mar 01 '24 07:03 mgehre-amd

Yeah, that makes perfect sense to me and should be pretty easy to fix.

A pull request is much appreciated, or I'll try to have a look sometime this weekend

keis avatar Mar 01 '24 10:03 keis

I don't see the behavior described

> git fixup 72b2e92867ffac015b0e16805c35b14a3a4fbc8a --rebase
Dummy always reject pre-commit
e71d3a7cb4a0ac43f96d55de5ba5c219311d0137
error: cannot rebase: Your index contains uncommitted changes.
error: Please commit or stash them.

Trying to call rebase after failing to commit is probably still a bug though. Could you share some more details of your setup? git versions, anything special going in the pre-commit?

keis avatar Mar 14 '24 13:03 keis

Hey, thanks for looking into it. I use pre-commit which checks/formats files. My flow is like

echo "extra lines" > existing.file
git add existing.file
git fixup
# pre-commit checks run. They format the file and fail with exit code 1. Now `existing.file` is both in the index (with my manual changes) and there are additional unstaged changes in the work tree from the formatting.

I think I don't get the error from the rebase because I use the git config rebase.autoStash = true

mgehre-amd avatar Mar 14 '24 13:03 mgehre-amd

I have that config setting too but I still see git rebase refusing to run with staged changes. Anyway the fix should be pretty easy, could you hive the version in #70 a go?

keis avatar Mar 14 '24 13:03 keis