Skip to content

Instantly share code, notes, and snippets.

@lorne-luo
Created July 4, 2019 00:22
Show Gist options
  • Save lorne-luo/2d6fbb6e97534e1a6905078a70408e52 to your computer and use it in GitHub Desktop.
Save lorne-luo/2d6fbb6e97534e1a6905078a70408e52 to your computer and use it in GitHub Desktop.
Git commit hook for python formatter black
#!/bin/sh
# see black https://github.com/python/black
set -e
if which black >/dev/null; then
REPO_ROOT_DIR="$(git rev-parse --show-toplevel)"
files=$((git diff --cached --name-only --diff-filter=ACMR | grep -Ei "\.py$") || true)
if [ ! -z "${files}" ]; then
black $files
git add "$files"
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment