Skip to content

Commit 07c76a3

Browse files
committed
Add some git hooks
1 parent 7efa55b commit 07c76a3

File tree

4 files changed

+43
-2
lines changed

4 files changed

+43
-2
lines changed

GitHooks/pre-commit

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/bash -e
2+
3+
# This is a PSR-2 checking example for just the code about to be committed
4+
5+
# Get the changes
6+
files=$(mktemp)
7+
diff=$(mktemp)
8+
9+
git diff --cached --name-only --diff-filter=ACMR -- "*.php" > ${files}
10+
git diff --cached > ${diff}
11+
12+
# Run the phpcs report
13+
phpcs=$(mktemp)
14+
./vendor/bin/phpcs --file-list=${files} --parallel=2 --standard=psr2 --report=json > ${phpcs} || true
15+
16+
check for differences
17+
./vendor/bin/diffFilter --phpcs diff.txt phpcs.json

GitHooks/pre-receive

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/bash
2+
3+
# This is a PSR-2 checking example for just the code about to be committed
4+
5+
# Get the changes
6+
files=$(mktemp)
7+
diff=$(mktemp)
8+
9+
git diff --name-only --diff-filter=ACMR -- "*.php" $1...$2 > ${files}
10+
git diff $1...$2 > ${diff}
11+
12+
# Run the phpcs report
13+
phpcs=$(mktemp)
14+
./vendor/bin/phpcs --file-list=${files} --parallel=2 --standard=psr2 --report=json > ${phpcs} || true
15+
16+
check for differences
17+
./vendor/bin/diffFilter --phpcs diff.txt phpcs.json

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ Coverage checker allows new standards to be implemented incrementally, by only e
99

1010
Tools like phpcs and phpmd are an all or nothing approach, coverage checker allows this to work with the diff i.e. enforce all of the pull request / change request.
1111

12+
This is sometimes called "Baselining"
13+
1214
Also working with PHPunit to allow, for example 90% of new/edited code to be covered. which will increase the overall coverage over time.
1315

1416
# Installing
@@ -54,6 +56,12 @@ diffFilter will exit with a `0` status if the changed code passes the minimum co
5456
## Extended guide
5557
A more in depth guide can be [found on the wiki](https://github.com/exussum12/coverageChecker/wiki) also some tips for speeding up the build.
5658

59+
## Installing as a git hook
60+
61+
There are 2 examples hooks in the GitHooks directory, if you symlink to these diffFilter will run locally.
62+
63+
pre-commit is before the commit happens
64+
pre-receive will prevent you pushing
5765

5866
# Full list of available diff filters
5967

examples/phpcsEnforce.sh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,11 @@ set -e
66

77
# Get the diff (changes since the branch was created
88
git diff origin/master... > diff.txt
9-
git diff origin/master... --name-only -- '*.php' > files.txt
9+
git diff origin/master... --name-only --diff-filter=ACMR -- '*.php' > files.txt
1010

1111

1212
# Old versions of phpcs will need to use the syntax commented out.
1313
# Note the || true is important, Without this phpcs failing will fail the build!
14-
# ./vendor/bin/phpcs --standard=psr2 src > phpcs.json || true
1514

1615
./vendor/bin/phpcs --file-list=files.txt --parallel=2 --standard=psr2 --report=json > phpcs.json || true
1716

0 commit comments

Comments
 (0)