Skip to content

Instantly share code, notes, and snippets.

@ericdill
Last active July 21, 2018 04:18
Show Gist options
  • Save ericdill/9940af172138f54b37e62003eb278810 to your computer and use it in GitHub Desktop.
Save ericdill/9940af172138f54b37e62003eb278810 to your computer and use it in GitHub Desktop.
Pre-commit hook that reformats your code according to yapf
#!/bin/bash
# capture the changed files that have been staged
changed_files=$(git diff --staged --name-only)
echo "Changed files: ${changed_files}"
for file in ${changed_files}
do
echo "Modifying ${file}"
yapf ${file} -i
git add ${file}
done
@ericdill
Copy link
Author

wget https://gist.githubusercontent.com/ericdill/9940af172138f54b37e62003eb278810/raw/pre-commit && mv pre-commit .git/hooks/pre-commit && chmod +x .git/hooks/pre-commit

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