Created
July 4, 2019 00:22
-
-
Save lorne-luo/2d6fbb6e97534e1a6905078a70408e52 to your computer and use it in GitHub Desktop.
Git commit hook for python formatter black
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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