Skip to content

Commit

Permalink
Junkchecker check whole phrasefile line (#52)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikaelz authored and greg0ire committed Sep 18, 2017
1 parent 4877b9c commit fd84fa8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
5 changes: 2 additions & 3 deletions template/hooks/junkchecker/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@ then
for FILE in $(git diff-index --cached --name-status $against -- | cut -c 3-); do
if [ -f "$FILE" ]
then
for line in $(cat "$junkchecker_phrases_file")
while IFS='' read -r line || [[ -n "$line" ]];
do

git diff --cached --diff-filter=ACMR "$FILE" | grep -E '^\+' | grep --quiet "$line"
if [ $? -eq 0 ]
then
Expand All @@ -24,7 +23,7 @@ then
EOT
exit 1
fi
done
done < "$junkchecker_phrases_file"
fi
done
else
Expand Down
12 changes: 12 additions & 0 deletions tests/junkchecker_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,18 @@ testExitsWithCodeEqualToZeroWhenJunkIsRemovedAndNotAdded()
assertEquals "The junkchecker should be ok with this commit" 0 $rtrn
}

testMultiWordPattern()
{
initRepo
echo "var_dump" > junk-phrases
echo "remove this debug line" >> junk-phrases
echo "// TODO remove this debug line" > someFile
git add someFile
git commit --message "Let's commit something we shouldn't" 1> /dev/null 2> "${stderrF}"
rtrn=$?
assertEquals "The junkchecker detected the junk" 1 $rtrn
}

initRepo()
{
cd "$testRepo"
Expand Down

0 comments on commit fd84fa8

Please sign in to comment.