Skip to content

Instantly share code, notes, and snippets.

@haggen
Created September 23, 2019 18:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save haggen/5e0422daf48c493556242d26c821f9ec to your computer and use it in GitHub Desktop.
Save haggen/5e0422daf48c493556242d26c821f9ec to your computer and use it in GitHub Desktop.
Random post-commit hook saved for later reference
#!/usr/bin/env bash
set -euxo pipefail
last-commited-files() {
git diff-tree --no-commit-id --name-only -r HEAD
}
message="Bumping"
last-commited-files | while read file; do
scripts/find-toc "$file"
done | sort -u | while read toc; do
if git diff-index --quiet HEAD "$toc" >/dev/null 2>&1; then
git stash push --quiet --message "$message" -- "$toc" #>/dev/null 2>&1
fi
scripts/bump "$toc" patch
git add "$toc" #>/dev/null 2>&1
git commit --amend --no-edit #>/dev/null 2>&1
stash="$(git stash list | grep "$message" | cut -d: -f1)"
if test -n "$stash"; then
git stash pop --quiet "$stash" #>/dev/null 2>&1
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment