Support local pre-commit checks.

Review Request #1883 - Created March 7, 2015 and submitted

Information
John Sirois
pants
jsirois/commit_hook/lints
1222
bace88d...
Reviewers
pants-reviews
benjyw, dturner-tw, lahosken, zundel
This change adds a setup script that will install or re-install a
pre-commit hook to run pants lints.  The pre-commit script is also
runnable directly to support a centralized stable script developers can
run to execute all lints independent of performing a commit.

 build-support/bin/check_header.sh         |  2 +-
 build-support/bin/check_packages.sh       |  2 +-
 build-support/bin/ci.sh                   | 11 ++++-------
 build-support/bin/isort.sh                |  2 +-
 build-support/bin/pre-commit.sh           | 11 +++++++++++
 build-support/bin/setup.sh                | 37 +++++++++++++++++++++++++++++++++++++
 build-support/common.sh                   |  4 ++++
 build-support/pants_venv                  |  4 ----
 src/python/pants/docs/howto_contribute.md | 12 ++++++++++++
 9 files changed, 71 insertions(+), 14 deletions(-)

Local testing:

# Install
$ rm -f .git/hooks/pre-commit
$ ./build-support/bin/setup.sh 
Pre-commit checks installed from /home/jsirois/dev/3rdparty/jsirois-pants3/build-support/bin/pre-commit.sh to /home/jsirois/dev/3rdparty/jsirois-pants3/.git/hooks/pre-commit
$ ./build-support/bin/setup.sh 
Pre-commit checks up to date.

# Unanticipated drift
$ rm -f .git/hooks/pre-commit
$ touch /home/jsirois/dev/3rdparty/jsirois-pants3/.git/hooks/pre-commit
$ ./build-support/bin/setup.sh 
A pre-commit script already exists, replace with /home/jsirois/dev/3rdparty/jsirois-pants3/build-support/bin/pre-commit.sh? [Yn]n
Pre-commit checks not installed
$ ./build-support/bin/setup.sh 
A pre-commit script already exists, replace with /home/jsirois/dev/3rdparty/jsirois-pants3/build-support/bin/pre-commit.sh? [Yn]
Pre-commit checks installed from /home/jsirois/dev/3rdparty/jsirois-pants3/build-support/bin/pre-commit.sh to /home/jsirois/dev/3rdparty/jsirois-pants3/.git/hooks/pre-commit
$ ./build-support/bin/setup.sh 
Pre-commit checks up to date.

# Dogfood on this commit
$ git commit
Checking packages
Checking imports
Checking headers
Success
[jsirois/lints/commit_hooks 8458f3e] Support local pre-commit checks.
 9 files changed, 71 insertions(+), 14 deletions(-)
 create mode 100755 build-support/bin/pre-commit.sh
 create mode 100755 build-support/bin/setup.sh

CI went green here:
https://travis-ci.org/pantsbuild/pants/builds/53506978

Issues

  • 0
  • 1
  • 0
  • 1
Description From Last Updated
John Sirois
Eric Ayers
Eric Ayers
John Sirois
John Sirois
John Sirois
Larry Hosken
John Sirois
John Sirois
Eric Ayers
John Sirois
John Sirois
Review request changed

Status: Closed (submitted)

David Turner

   
build-support/bin/setup.sh (Diff revision 4)
 
 

Why not just use cmp to compare the files?

(also, md5 should never be used; I know it is unlikely to be an issue here but it seems better to avoud promoting bad practices)

  1. I did not know of cmp - I'll send a new RB shortly to switch.
    As far as the inadvisability of md5 ... the hashing here is not pretending or trying to be attack resistant.  Any low-probability under non-malicious use hash will do.
  2. https://rbcommons.com/s/twitter/r/1892/
David Turner
Ship It!
Loading...