#!/bin/bash

[ -z "$REVRANGE" ] && REVRANGE="master..HEAD^1"

# get a list of changed files, used below; this uses a tempfile to work around
# shell behavior when piping to 'while'
tempfile=$(mktemp -t tmp.XXXXXX)
trap "rm -f ${tempfile}; exit 1" 1 2 3 15

git diff --name-only $REVRANGE | grep '\.py$' > ${tempfile}

py_files=()
while read line; do
    if [[ -f "${line}" ]]; then
        echo "fast-styling ${line}"
        pipenv run fiximports ${line};
    fi
done < ${tempfile}
