Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions development.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ To get cracking with Unison:

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.

## Git hooks

There are some Git hooks provided by Unison. If you want to use them, you can run

``` bash
./scripts/install-hooks.bash
```

## Autoformatting your code with Ormolu

We use Ormolu (see [the specific version](./nix/versions.nix)) and CI will add an extra commit, if needed, to autoformat your code.
Expand Down
36 changes: 33 additions & 3 deletions scripts/install-hooks.bash
Original file line number Diff line number Diff line change
@@ -1,9 +1,39 @@
#!/usr/bin/env bash
set -euo pipefail
SCRIPTNAME="$(readlink -f -- "${BASH_SOURCE[0]}")"
SCRIPTDIR="$(dirname -- "$SCRIPTNAME")"

GIT_DIR=$(git rev-parse --git-dir)
function usage {
echo "Usage: $SCRIPTNAME [-f] [-h]"
echo
echo " -f Overwrite hooks if they already exist"
echo " -h Show this usage message"
}

trap "echo; usage" ERR

force=("-n")
while getopts ':fh' OPTION; do
case "$OPTION" in
f)
force=("-f")
;;
h)
usage
exit 0
;;
\?)
usage
exit 1
;;
esac
done

hooks_dir=$(git rev-parse --git-path hooks)

echo "Installing hooks..."
mkdir -p "$hooks_dir"
# this command creates symlink to our pre-commit script
ln -s ../../scripts/pre-commit.bash $GIT_DIR/hooks/pre-commit
ln -s ../../scripts/pre-push.bash $GIT_DIR/hooks/pre-push
cp "${force[@]}" "$SCRIPTDIR/pre-commit.bash" "$hooks_dir/pre-commit"
cp "${force[@]}" "$SCRIPTDIR/pre-push.bash" "$hooks_dir/pre-push"
echo "Done!"
11 changes: 5 additions & 6 deletions scripts/pre-commit.bash
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
#!/usr/bin/env bash
set -euo pipefail

echo "Running pre-commit hook from "`pwd`
./scripts/test.sh
echo "Running pre-commit hook from $(pwd)"

# $? stores exit value of the last command
if [ $? -ne 0 ]; then
echo "Tests must pass before commit!"
exit 1
if ! ./scripts/test.sh; then
echo "Tests must pass before commit!"
exit 1
fi
14 changes: 6 additions & 8 deletions scripts/pre-push.bash
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
#!/bin/bash
# Run the following command in the root of your project to install this pre-push hook:
# cp git-hooks/pre-push .git/hooks/pre-push; chmod 700 .git/hooks/pre-push
set -euo pipefail

# Run `./install-hooks.bash` to install this pre-push hook.

# Check if we actually have commits to push
commits=`git log @{u}..`
commits=$(git log "@{u}..")
if [ -z "$commits" ]; then
exit 0
fi

CMD="./scripts/test.sh"
eval $CMD
RESULT=$?
if [ $RESULT -ne 0 ]; then
echo "The git push operation was canceled because \`$CMD\` did not complete successfully."
if ! "$CMD"; then
echo "The git push operation was canceled because ‘$CMD’ did not complete successfully."
exit 1
fi
exit 0
Loading