Skip to content

Instantly share code, notes, and snippets.

@stubb
Created July 18, 2012 13:19
Show Gist options
  • Save stubb/3136167 to your computer and use it in GitHub Desktop.
Save stubb/3136167 to your computer and use it in GitHub Desktop.
A git post-commit hook which searches for deleted .py files in HEAD and removes the corresponding .pyc files.
#!/bin/sh
#
# This post commit hook searches for deleted .py files in HEAD and removes the
# corresponding .pyc files.
#
deleted_files = 'git show --pretty="format:" --name-only HEAD --diff-filter=D'
for i in ${deleted_files[@]}; do
file_ending=$(echo $i | grep -o "...$")
if [ $file_ending == '.py' ] ; then
rm ${i}c
fi
done
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment