Skip to content

Instantly share code, notes, and snippets.

@matthieuprat
Last active September 13, 2015 00:59
Show Gist options
  • Save matthieuprat/a9ee3c56d8677bead02e to your computer and use it in GitHub Desktop.
Save matthieuprat/a9ee3c56d8677bead02e to your computer and use it in GitHub Desktop.
#! /bin/bash
while read -r f
do
if $(git diff-files --quiet -- ":(literal)$f")
then
# Check the file in the worktree since there are no unstaged changes.
flake8 "$f" || err=1
else
# Pipe staged changes to flake8 and replace 'stdin:<error>' with
# '<filename>(staged):<error>'.
git cat-file -p ":$f" | flake8 - | sed "s|^stdin|${f/|/\\|}(staged)|"
[ "${PIPESTATUS[1]}" = "0" ] || err=1
fi
done < <(git diff-index --diff-filter=AM --cached --name-only HEAD -- \*.py)
exit ${err-0}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment