Skip to content

Commit 2ad0e32

Browse files
committed
Fix install-hooks.bash script
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 - when run it from anywhere in the repo (not just from two directories down somewhere), - when `core.hooksPath` is set (i.e., `$GIT_DIR/hooks` isn’t the right place), - when run from a worktree (which doesn’t necessarily have its own hooks dir), and - when the hooks directory doesn’t exist.
1 parent 27c18a4 commit 2ad0e32

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

development.markdown

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,14 @@ To get cracking with Unison:
2020

2121
On startup, Unison prints a url for the codebase UI. If you did step 3 above, then visiting that URL in a browser will give you a nice interface to your codebase.
2222

23+
## Git hooks
24+
25+
There are some Git hooks provided by Unison. If you want to use them, you can run
26+
27+
``` bash
28+
./scripts/install-hooks.bash
29+
```
30+
2331
## Autoformatting your code with Ormolu
2432

2533
We use Ormolu (see [the specific version](./nix/versions.nix)) and CI will add an extra commit, if needed, to autoformat your code.

scripts/install-hooks.bash

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
#!/usr/bin/env bash
2+
set -euo pipefail
3+
SCRIPTDIR="$(dirname -- "$(readlink -f -- "${BASH_SOURCE[0]}")")"
24

3-
GIT_DIR=$(git rev-parse --git-dir)
5+
hooks_dir=$(git rev-parse --git-path hooks)
46

57
echo "Installing hooks..."
8+
mkdir "$hooks_dir"
69
# this command creates symlink to our pre-commit script
7-
ln -s ../../scripts/pre-commit.bash $GIT_DIR/hooks/pre-commit
8-
ln -s ../../scripts/pre-push.bash $GIT_DIR/hooks/pre-push
10+
ln -s "$SCRIPTDIR/pre-commit.bash" "$hooks_dir/pre-commit"
11+
ln -s "$SCRIPTDIR/pre-push.bash" "$hooks_dir/pre-push"
912
echo "Done!"

0 commit comments

Comments
 (0)