Skip to content

Instantly share code, notes, and snippets.

@bkonetzny
Last active February 21, 2020 09:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bkonetzny/cb4aeec57f9207d8f9162269b8342abc to your computer and use it in GitHub Desktop.
Save bkonetzny/cb4aeec57f9207d8f9162269b8342abc to your computer and use it in GitHub Desktop.
Check a list of changed files, e.g. run through php-cs-fixer
#!/bin/bash
BRANCH=master
git diff --name-status ${BRANCH} | \
while read -r status srcfile destfile
do
if [ -z "$destfile" ]
then
# Use source file (e.g. modified)
changedfile=$srcfile
else
# Use destination file (e.g. moved)
changedfile=$destfile
fi
# Skip deleted or non-PHP files
if [[ $status != 'D' && $changedfile == *".php" ]]; then
echo "Fixing file ${changedfile}"
php-cs-fixer fix "${changedfile}"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment