forked from twitter/pants
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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. Testing Done: Local testing: ```console # 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 Bugs closed: 1222 Reviewed at https://rbcommons.com/s/twitter/r/1883/
- Loading branch information
Showing
9 changed files
with
84 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#!/usr/bin/env bash | ||
|
||
# NB: pre-commit runs in the context of GIT_WORK_TREE, ie: pwd == REPO_ROOT | ||
|
||
source build-support/common.sh | ||
|
||
echo "Checking packages" && ./build-support/bin/check_packages.sh || exit 1 | ||
echo "Checking imports" && ./build-support/bin/isort.sh || \ | ||
die "To fix import sort order, run \`build-support/bin/isort.sh -f\`" | ||
echo "Checking headers" && ./build-support/bin/check_header.sh || exit 1 | ||
echo "Success" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#!/usr/bin/env bash | ||
|
||
# Set up the development environment. | ||
# Currently this just installs local git hooks. | ||
|
||
REPO_ROOT="$(git rev-parse --show-toplevel)" | ||
|
||
HOOK_DIR="${GIT_DIR:-${REPO_ROOT}/.git}/hooks" | ||
PRE_COMMIT_DEST="${HOOK_DIR}/pre-commit" | ||
PRE_COMMIT_SRC="${REPO_ROOT}/build-support/bin/pre-commit.sh" | ||
PRE_COMMIT_RELSRC="$(cat << EOF | python2.7 | ||
import os | ||
print(os.path.relpath("${PRE_COMMIT_SRC}", "${HOOK_DIR}")) | ||
EOF | ||
)" | ||
|
||
source "${REPO_ROOT}/build-support/common.sh" | ||
|
||
function install_pre_commit_hook() { | ||
( | ||
cd "${HOOK_DIR}" && \ | ||
rm -f pre-commit && \ | ||
ln -s "${PRE_COMMIT_RELSRC}" pre-commit && \ | ||
echo "Pre-commit checks linked from ${PRE_COMMIT_SRC} to $(pwd)/pre-commit"; | ||
) | ||
} | ||
|
||
if [[ ! -e "${PRE_COMMIT_DEST}" ]] | ||
then | ||
install_pre_commit_hook | ||
else | ||
existing_hook_sig="$(cat "${PRE_COMMIT_DEST}" | fingerprint_data)" | ||
canonical_hook_sig="$(cat "${PRE_COMMIT_SRC}" | fingerprint_data)" | ||
if [[ "${existing_hook_sig}" != "${canonical_hook_sig}" ]] | ||
then | ||
read -p "A pre-commit script already exists, replace with ${PRE_COMMIT_SRC}? [Yn]" ok | ||
if [[ "${ok:-Y}" =~ ^[yY]([eE][sS])?$ ]] | ||
then | ||
install_pre_commit_hook | ||
else | ||
echo "Pre-commit checks not installed" | ||
exit 1 | ||
fi | ||
else | ||
echo "Pre-commit checks up to date." | ||
fi | ||
fi | ||
exit 0 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters