Skip to content

Commit

Permalink
Merge pull request #44 from greg0ire/prevent_path_globbing
Browse files Browse the repository at this point in the history
Prevent path globbing
  • Loading branch information
greg0ire authored Jun 30, 2016
2 parents 3547061 + c96ae70 commit 1698067
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
22 changes: 11 additions & 11 deletions template/hooks/change_detector.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
has_changed()
{
local hook_type=$1; shift
local monitored_paths=($@)
local monitored_paths=("$@")
local against
local changed

Expand All @@ -30,16 +30,16 @@ has_changed()
-- ${monitored_paths[*]}| wc -l)"
;;
pre-commit)
if git rev-parse --verify HEAD >/dev/null 2>&1
then
against=HEAD
else
# Initial commit: diff against an empty tree object
against=4b825dc642cb6eb9a060e54bf8d69288fbee4904
fi
changed="$(git diff-index \
--name-status $against \
-- ${monitored_paths[*]} | wc -l)"
if git rev-parse --verify HEAD >/dev/null 2>&1
then
against=HEAD
else
# Initial commit: diff against an empty tree object
against=4b825dc642cb6eb9a060e54bf8d69288fbee4904
fi
changed="$(git diff-index \
--name-status $against \
-- "${monitored_paths[*]}" | wc -l)"
;;
esac

Expand Down
2 changes: 1 addition & 1 deletion template/hooks/php/cs-fixer/pre-commit
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash
. "$GIT_DIR/hooks/change_detector.sh"

if has_changed pre-commit ./**/*.php ./*.php
if has_changed pre-commit '**/*.php' '*.php'
then
.git/hooks/php/cs-fixer/fix-cs
fi
6 changes: 3 additions & 3 deletions tests/php/phpcs_fixer_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ testRunsPhpCsFixerOnPhpFileChange()
export -f phpcsfixer
export SHUNIT_TMPDIR
initRepo
mkdir --parents a/b/c.php
echo "a" > c.php
git add c.php
mkdir --parents a/b
echo "a" > a/b/c.php
git add a/b/c.php
git commit --quiet --message "first version of c.php"
assertTrue 'PhpCsFixer was not run' "[ $(cat "${SHUNIT_TMPDIR}/phpCsFixerWasRun") == fix ]"
rm "${SHUNIT_TMPDIR}/phpCsFixerWasRun"
Expand Down

0 comments on commit 1698067

Please sign in to comment.