tummychow / git-absorb

git commit --fixup, but automatic
https://crates.io/crates/git-absorb
BSD 3-Clause "New" or "Revised" License
3.38k stars 58 forks source link

Respect pre-commit hooks #48

Open joao-p-marques opened 2 years ago

joao-p-marques commented 2 years ago

Hi! :wave:

First of all, thanks for the great project.

I am finding that, when running the command, it does not follow any hooks I have defined for the project (especially important with pre-commit hooks). Is there a way of forcing it with the current code by changing any configuration?

tummychow commented 2 years ago

we're at the mercy of upstream for this: https://github.com/libgit2/libgit2/pull/4620 and i would rather not hand-roll an implementation of hooks without upstream support

Le09 commented 2 years ago

Hi! Thanks for the great project, git-absorb is really a fantastic help! Whether there is CI checking the linting or not, respecting hooks is a must. What would be the simplest workaround? I do: git add -u; git commit -m "*"; git reset HEAD~; git add -u; git absorb --and-rebase However it's quite cumbersome, it's worse if there's a need to do a selective add, and terrible if there's a need for a -p commit. (the last workflow is broken in all cases by pre-commit, so -n should be added to apply the same method afterwards)

Are there simpler alternatives?

tummychow commented 2 years ago

honestly, i do not know of any workarounds.

Le09 commented 2 years ago

All right, thanks for the reply :-)

Le09 commented 2 years ago

Best wishes for the new year! I just had another perspective about the subject. Isn't there a way to integrate pre-commit simply by running it on all modified files on the feature branch after the absorb phase? If there are changes, you can then inspect them and rewrite as needed, and after that run absorb again. That would reproduce the original workflow. (if not, I guess it could also be done by creating a bash function as workaround)

tummychow commented 2 years ago

sorry, but like i said before, i'm not interested in hand-rolling an implementation of hooks, period. there has to be upstream support for running them the right way.

Le09 commented 2 years ago

That's fine by me. The workaround I was thinking about is the following:

function absorbpre() {
    FS=$(git diff --cached --name-status | cut -f2 | tr '\n' ' ')
    git absorb --and-rebase 
    pre-commit run --files $FS
}

Which to me solves the problem in a satisfying way, as opposed to the previous one.

Thank you again for your work.