top | item 45639937

(no title)

ozzydave | 4 months ago

pre-commit hooks are awful, they get in the way of interactive rebasing. pre-push is where they belong; save a round-trip through CI.

discuss

order

jakub_g|4 months ago

You can check inside the hook if you're in the middle of the rebase, and exit the hook early.

This is what we have in our hooks:

    if [ -d "$(git rev-parse --git-path rebase-merge)" ] || \
       [ -d "$(git rev-parse --git-path rebase-apply)" ] || \
       [ -f "$(git rev-parse --git-path MERGE_HEAD)" ]; then
        exit 0
    fi

rmwaite|4 months ago

Thanks for this, I can’t believe this never occurred to me to try to do.

hambes|4 months ago

I would argue that if the pre-commit hooks come in the way of rebasing, either the commit hooks are doing way too much (which is one of the points of the article) or you are creating broken commits during rebasing. If any of the commits you are rebasing is e.g. breaking formatting rules, they shouldn't have been committed that way in the first place.

conradludgate|4 months ago

I personally avoid pre-commit hooks and instead use git rebase -x "hook" to ensure my commits are not broken

motorest|4 months ago

> I would argue that if the pre-commit hooks come in the way of rebasing, either the commit hooks are doing way too much (which is one of the points of the article) or you are creating broken commits during rebasing.

I don't think your argument is grounded on reality. Applying whitespace changes does create merge conflicts, and if you have a hook that is designed to introduce said white changes at each commit of a rebase them you are going to have frequent merge conflicts.

Keep also in mind that minor changes such as renaming a variable can and will introduce line breaks. Thus even with a pristine codebase that was formatted to perfection you will get merge conflicts.

> If any of the commits you are rebasing is e.g. breaking formatting rules, they shouldn't have been committed that way in the first place.

You're letting the world know you have little to no programming experience.

extr|4 months ago

Yeah there's really no trouble with a pre-push hook that runs common/fast code checks. For TS projects I just run formatting, type, and lint checks. Faster feedback than spinning up a runner in CI and if I don't need it I just tack on --no-verify.

motorest|4 months ago

> For TS projects I just run formatting, type, and lint checks.

For formatting I find that it's clearly preferable to lean on the IDE and apply the source code formatter at each file save, and apply it only to the file you are touching. Type checks should be performed right before running unit tests, for the same reason unit tests are executed.

echelon|4 months ago

Database integrity constraints fall into the same category.

This entire class of automation is awful and defeats the robustness of the tool itself.

All of these things have terribly unpredictable consequences and tend to fail at the worst moments, such as during a SEV.

You can encode the same rules and discipline in other ways that do not impact the health of the system, the quality of the data, or the ability of engineers to do work.

esafak|4 months ago

agents trip up over them too.