Skip to content

Instantly share code, notes, and snippets.

@travisjungroth
Created January 23, 2023 04:29
Show Gist options
  • Save travisjungroth/325787d62fb3fb80358b9160bd97a026 to your computer and use it in GitHub Desktop.
Save travisjungroth/325787d62fb3fb80358b9160bd97a026 to your computer and use it in GitHub Desktop.
Run the pre-commit tool and commit any changes. Save to .git/hooks/post-commit or add as a line.
#!/usr/bin/env bash
messages=$(git log --format=%s -3)
repeated="autocommit
autocommit
autocommit"
if [ "$messages" = "$repeated" ]; then
echo "3 times, enough already."
exit 1
fi
changed=$(git diff --name-only HEAD HEAD^)
pre-commit run --files $changed
git add $changed
if ! git diff --cached --quiet ; then
git commit -m "autocommit"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment