diff --git a/.github/workflows/shellcheck.yml b/.github/workflows/shellcheck.yml new file mode 100644 index 0000000..0c3b95c --- /dev/null +++ b/.github/workflows/shellcheck.yml @@ -0,0 +1,23 @@ +name: ShellCheck + +on: + push: + branches: [master] + pull_request: + branches: [master] + +permissions: + contents: read + +jobs: + shellcheck: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Install ShellCheck + run: sudo apt-get install -y shellcheck + + - name: Run ShellCheck on all hooks + run: | + shellcheck pre-commit commit-msg pre-push post-checkout post-commit post-merge diff --git a/README.md b/README.md index 3af98ba..d2c70c3 100644 --- a/README.md +++ b/README.md @@ -39,42 +39,39 @@ a couple of annoying blunders: ## Installation -### Quick Install +### Quick Install (recommended) ```bash git clone https://github.com/taigrr/hooks.git ~/.git-hooks -git config --global core.hooksPath ~/.git-hooks +cd ~/.git-hooks && ./install.sh +``` + +This sets `core.hooksPath` so **all** repos use these hooks. Updates to the +hooks directory apply everywhere immediately. + +To override hooks for a specific repo: + +```bash +cd /path/to/repo +git config core.hooksPath /path/to/other/hooks ``` ### Template Installation -Use this if you want new repos to get a *copy* of the hooks at clone/init time: +Use this if you only want **new** repos (created with `git init` or `git clone`) +to receive a copy of these hooks: ```bash git clone https://github.com/taigrr/hooks.git ~/.git-hooks -git config --global init.templatedir ~/.git-hooks +cd ~/.git-hooks && ./install.sh --template ``` -> **Note:** Existing repos won't be affected — only newly cloned or initialized repos -> will receive the hooks. +> **Note:** Existing repos won't be affected. -### Central Management Installation - -Use this if you want *all* repos (existing and new) to use the same hooks directory: +### Uninstall ```bash -git clone https://github.com/taigrr/hooks.git ~/.git-hooks -git config --global core.hooksPath ~/.git-hooks -``` - -This has the benefit of updating the hooks for all repos when you make a change, -instead of only new repos going forward, but will require you to specify manual -overrides for individual repos with customized hooks: - -```bash -# Override for a specific repo -cd /path/to/repo -git config core.hooksPath /path/to/other/hooks +cd ~/.git-hooks && ./uninstall.sh ``` ## Configuration diff --git a/install.sh b/install.sh new file mode 100755 index 0000000..b70222e --- /dev/null +++ b/install.sh @@ -0,0 +1,18 @@ +#!/usr/bin/env bash +# Install git hooks globally via core.hooksPath. +# Usage: ./install.sh [--template] +# --template Use init.templateDir instead (only affects new repos) + +set -euo pipefail + +hook_dir="$(cd "$(dirname "$0")" && pwd)" + +if [ "${1:-}" = "--template" ]; then + git config --global init.templateDir "$hook_dir" + echo "Installed: init.templateDir set to $hook_dir" + echo "New repos created with git init/clone will copy these hooks." +else + git config --global core.hooksPath "$hook_dir" + echo "Installed: core.hooksPath set to $hook_dir" + echo "All repos will use hooks from $hook_dir." +fi diff --git a/uninstall.sh b/uninstall.sh new file mode 100755 index 0000000..68372a0 --- /dev/null +++ b/uninstall.sh @@ -0,0 +1,17 @@ +#!/usr/bin/env bash +# Remove global git hooks configuration set by install.sh. + +set -euo pipefail + +if git config --global --get core.hooksPath > /dev/null 2>&1; then + git config --global --unset core.hooksPath + echo "Removed core.hooksPath" +elif git config --global --get init.templateDir > /dev/null 2>&1; then + git config --global --unset init.templateDir + echo "Removed init.templateDir" +else + echo "No global hooks configuration found." + exit 0 +fi + +echo "Global hooks configuration cleared."