Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Run flake8 against only files that have changed
set -e
enable_env() {
local env_name="$1"
local env_dir=".tox/${env_name}"
if [ ! -d "${env_dir}" ]; then
if [ ! -f tox.ini ]; then
echo 'No tox.ini found' >&2
exit 1
elif tox -l | grep -q "^${env_name}$$"; then
tox -e"${env_name}" --notest
echo "No ${env_name} tox environment found" >&2
exit 1
source "${env_dir}"/bin/activate
diff_files_branch() {
local branch=${1:-"@{u}"}
git diff --name-only --diff-filter=d "${branch}" -- '*.py'
diff_files() {
diff_files_branch 2>/dev/null || diff_files_branch origin/master
enable_env pep8
flake8 $(diff_files)
Copy link

tbreeds commented Jun 20, 2019

So you've hardcoded origin/master on line 28 can you use @{u} or maybe $(git rev-parse --abbrev-ref --symbolic-full-name @{u}) so it works on stable branches?

Copy link

zaneb commented Jun 21, 2019

It does use @{u} (see line 23) and only falls back to origin/master if that fails. So it does the Right Thing on stable branches and falls back to diffing against master if you're working on e.g. a detached HEAD.

Copy link

tbreeds commented Jun 21, 2019

Ahh okay somehow I missed the '||' my mistake

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