Skip to content

Instantly share code, notes, and snippets.

@KingMob
Created June 25, 2023 10:56
Show Gist options
  • Save KingMob/d338dcc293cb0e4852495aae93b821d0 to your computer and use it in GitHub Desktop.
Save KingMob/d338dcc293cb0e4852495aae93b821d0 to your computer and use it in GitHub Desktop.
git pre-commit hook that runs a script when project.clj file has been modified
#!/usr/bin/env bash
# Move this to .git/hooks/pre-commit
# echo "Running pre-commit hook..."
# Check if project.clj file has been modified
if git diff --cached --name-only | grep -q "^project.clj$"; then
echo "project.clj modified, running lein-to-deps"
repo_root=$(git rev-parse --show-toplevel)
# Check the exit status of the script
if ! "$repo_root"/deps/lein-to-deps; then
echo "lein-to-deps script failed. Aborting commit."
exit 1
fi
fi
# If the "lein-to-deps" script succeeded,
# allow the commit to proceed
exit 0
@KingMob
Copy link
Author

KingMob commented Jun 25, 2023

Should also make a pre-merge-commit script that invokes this for merges, like:

#!/usr/bin/env bash

# Move this to .git/hooks/pre-merge-commit

# echo "Running pre-merge-commit..."

. git-sh-setup
test -x "$GIT_DIR/hooks/pre-commit" &&
        exec "$GIT_DIR/hooks/pre-commit"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment