Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uninstall pre-commit hooks when they are disabled #198

Open
domenkozar opened this issue Nov 29, 2022 · 3 comments
Open

Uninstall pre-commit hooks when they are disabled #198

domenkozar opened this issue Nov 29, 2022 · 3 comments

Comments

@domenkozar
Copy link
Member

In the shell code, if the user removed all hooks, uninstall the hook.

@domenkozar
Copy link
Member Author

For this to work reliably, we'd need to mark that it was installed by pre-commit-hooks.nix

@roberth
Copy link
Contributor

roberth commented Dec 23, 2022

This would be detectable if we customize the hook installation more. Nixpkgs already patches that code, but the gc root management isn't up to par yet. We may also want to move the config file from <proj>/.pre-commit-hooks.yaml to <proj>/.git/hooks/.pre-commit-hooks-nix.yaml + <proj>/.git/hooks/.pre-commit-bin for the program. All reasons to patch the hook generation code, and all detectable just by reading the generated hook script <proj>/.git/hooks/<hook>.

Currently it looks like

#!/nix/store/znkypmyvykawwg71xawqzb98qbllijv8-bash-5.1-p16/bin/bash
# File generated by pre-commit: https://pre-commit.com
# ID: 138fd403232d2ddd5efb44317e38bf03

# start templated
INSTALL_PYTHON=/nix/store/9srs642k875z3qdk8glapjycncf2pa51-python3-3.10.7/bin/python3.10
ARGS=(hook-impl --config=.pre-commit-config.yaml --hook-type=pre-commit)
# end templated

HERE="$(cd "$(dirname "$0")" && pwd)"
ARGS+=(--hook-dir "$HERE" -- "$@")

exec /nix/store/5d25296lls7rvrqc62jxvcwsyg60q4ag-python3.10-pre-commit-2.20.0/bin/pre-commit "${ARGS[@]}"

The last line only tells us that pre-commit from Nixpkgs was used.
If we change that to a local gcroot symlink in the hooks directory, we'll know that we manage it.

@domenkozar
Copy link
Member Author

Sound good to me!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants