Fix install-hooks.bash script #5910
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Overview
I hadn’t realized there were Git hooks, but noticed them when I was adding the Weeder script.
So, I documented that they exist, and then fixed the script since it wasn’t working for me.
It now works
core.hooksPath
is set (i.e.,$GIT_DIR/hooks
isn’t the right place),-f
).Implementation notes
This also replaces
ln -s
withcp
so that in case the particular worktree it was run from is renamed or deleted, it doesn’t break the hooks for the repository.Interesting/controversial decisions
I didn’t change this, but I don’t think a pre-commit hook should check that tests pass (or even that compilation succeeds). It’s good practice to commit failing tests ahead of the fix, for example. Or to rearrange code in one commit, and then fix the compilation errors in the next.
However, passing
--no-verify
to a git command will bypass its hooks, so it’s still easy enough to do those things with these hooks in place.Having tests be part of pre-push makes more sense, because you may be pushing to an open PR and don’t want to have to force push or add a new commit when you realize you just pushed broken code. And it’s still useful to push broken tests (so you can see CI failures), but the “publishing” nature of
push
means you’d want to be more careful about it.