Skip to content

Commit fe191c5

Browse files
Merge pull request #4696 from wp-cli/git-pre-commit-only-check-staged-files
Only check staged files during the pre-commit PHPCS verification
2 parents 4a1cb3f + 380a0f9 commit fe191c5

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

utils/git-pre-commit-script

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/bash
2+
3+
if REV=$(git rev-parse -q --verify HEAD); then
4+
against=HEAD
5+
else
6+
# Initial commit: diff against an empty tree object
7+
against=4b825dc642cb6eb9a060e54bf8d69288fbee4904
8+
fi
9+
10+
FILES=$(git diff-index --name-only --cached --diff-filter=ACMR $against -- )
11+
12+
if [ "$FILES" == "" ]; then
13+
echo "No files to check with PHPCS."
14+
exit 0
15+
fi
16+
17+
set -ex
18+
19+
{{PHPCS_BIN}} -s $FILES

utils/git-setup-pre-commit-hook

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ fi
2525
pre_commit_file="$(git rev-parse --git-dir)/hooks/pre-commit"
2626

2727
if [[ ! -f "$pre_commit_file" ]]; then
28-
echo -e "#!/bin/bash\nset -ex\n$phpcs_bin" > $pre_commit_file
28+
cat utils/git-pre-commit-script | sed 's|{{PHPCS_BIN}}|'$phpcs_bin'|' > $pre_commit_file
2929
chmod +x $pre_commit_file
3030
elif ! grep -q "phpcs" $pre_commit_file; then
3131
echo -e "hook file already exists: $pre_commit_file\n\nplease add the below command to your pre-commit file:\n\n$phpcs_bin"

0 commit comments

Comments
 (0)