Skip to content

wtfzdotnet/diff-sniffer

 
 

Repository files navigation

Diff Sniffer for Git

PHP Version Latest Stable Version Build Status AppVeyor Build Status Code Coverage

This tool allows you to use PHP_CodeSniffer as a pre-commit hook. The main difference from existing solutions that this one validates only changed lines of code but not the whole source tree.

Installation

Download a PHAR package of the latest release and put it somewhere within your $PATH:

$ wget https://github.com/diff-sniffer/diff-sniffer/releases/latest/download/diff-sniffer.phar
$ chmod +x diff-sniffer.phar
$ sudo cp diff-sniffer.phar /usr/local/bin/diff-sniffer

Create a pre-commit hook in a specific Git repository .

$ cd /path/to/repo
$ cat > .git/hooks/pre-commit << 'EOF'
#!/usr/bin/env bash

diff-sniffer --staged "$@"
EOF

Alternatively, you can create a global pre-commit hook for your user (see man githooks):

$ cat > ~/.config/git/hooks/pre-commit << 'EOF'
#!/usr/bin/env bash

diff-sniffer --staged "$@"
EOF

You can also install Diff Sniffer manually:

$ git clone [email protected]:diff-sniffer/diff-sniffer.git
$ cd diff-sniffer
$ composer install
$ bin/diff-sniffer --version

Continuous integration mode

Diff Sniffer can also run on a CI server and validate pull requests. For example, on Travis CI:

$ wget https://github.com/diff-sniffer/diff-sniffer/releases/latest/download/diff-sniffer.phar
$ php diff-sniffer.phar origin/$TRAVIS_BRANCH...$TRAVIS_PULL_REQUEST_SHA

About

Diff Sniffer for Git

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 98.9%
  • Other 1.1%