mirror of
https://ghproxy.net/https://github.com/wp-cli/wp-cli-bundle.git
synced 2025-10-04 00:09:45 +08:00
Merge pull request #4696 from wp-cli/git-pre-commit-only-check-staged-files
Only check staged files during the pre-commit PHPCS verification
This commit is contained in:
commit
974915f712
2 changed files with 20 additions and 1 deletions
19
utils/git-pre-commit-script
Executable file
19
utils/git-pre-commit-script
Executable file
|
@ -0,0 +1,19 @@
|
|||
#!/bin/bash
|
||||
|
||||
if REV=$(git rev-parse -q --verify HEAD); then
|
||||
against=HEAD
|
||||
else
|
||||
# Initial commit: diff against an empty tree object
|
||||
against=4b825dc642cb6eb9a060e54bf8d69288fbee4904
|
||||
fi
|
||||
|
||||
FILES=$(git diff-index --name-only --cached --diff-filter=ACMR $against -- )
|
||||
|
||||
if [ "$FILES" == "" ]; then
|
||||
echo "No files to check with PHPCS."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
set -ex
|
||||
|
||||
{{PHPCS_BIN}} -s $FILES
|
|
@ -25,7 +25,7 @@ fi
|
|||
pre_commit_file="$(git rev-parse --git-dir)/hooks/pre-commit"
|
||||
|
||||
if [[ ! -f "$pre_commit_file" ]]; then
|
||||
echo -e "#!/bin/bash\nset -ex\n$phpcs_bin" > $pre_commit_file
|
||||
cat utils/git-pre-commit-script | sed 's|{{PHPCS_BIN}}|'$phpcs_bin'|' > $pre_commit_file
|
||||
chmod +x $pre_commit_file
|
||||
elif ! grep -q "phpcs" $pre_commit_file; then
|
||||
echo -e "hook file already exists: $pre_commit_file\n\nplease add the below command to your pre-commit file:\n\n$phpcs_bin"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue