Skip to content

Instantly share code, notes, and snippets.

@Kidde82
Created April 11, 2018 11:35
Show Gist options
  • Select an option

  • Save Kidde82/22aeb5e76a9ef96867a0c74b051441eb to your computer and use it in GitHub Desktop.

Select an option

Save Kidde82/22aeb5e76a9ef96867a0c74b051441eb to your computer and use it in GitHub Desktop.
Pre-Commit Hook
#!/bin/sh
TEMPDIR="tmp"
RED=`tput setaf 1`
GREEN=`tput setaf 2`
RESET=`tput sgr0`
rm -rf $TEMPDIR
mkdir -p $TEMPDIR
git checkout-index --prefix=$TEMPDIR/ -af
INCLUDESTR="$(git diff --cached --name-only --diff-filter=ACM | xargs -n 1 -I file echo $TEMPDIR/file | grep .cs | tr '\n' ';')"
INCLUDESTR=${INCLUDESTR//"tmp/"/"*"}
SOLUTIONFILE="$(find ./$TEMPDIR -name *.sln)"
md5sum $TEMPDIR/**/*.* > checklist.chk
echo "${GREEN}Running CleanUpCode-Check${RESET}"
: $(cleanupcode.exe --include="$INCLUDESTR" $SOLUTIONFILE)
MD5ERROR="$(md5sum -c checklist.chk --quiet)"
rm -rf $TEMPDIR
rm checklist.chk
if [ "${#MD5ERROR}" = "0" ] ; then
echo "${GREEN}CleanUpCode-Check passed, continue commit${RESET}"
exit 0
else
echo "${RED}CleanUpCode-Check failed, aborting commit${RESET}"
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment