From 27c9967c61ab767b2e18eb9d0498f4589790df9a Mon Sep 17 00:00:00 2001 From: Stu Hood Date: Mon, 4 Feb 2019 16:28:26 -0800 Subject: [PATCH 1/2] Many hooks are only valid in a working copy containing master: move them all under the relevant check for master. --- build-support/bin/pre-commit.sh | 43 +++++++++++++++++---------------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/build-support/bin/pre-commit.sh b/build-support/bin/pre-commit.sh index f6e0d075345..384c1f14dda 100755 --- a/build-support/bin/pre-commit.sh +++ b/build-support/bin/pre-commit.sh @@ -51,36 +51,37 @@ printf "%s\n" "${ADDED_FILES[@]}" \ echo "* Checking for banned imports" ./build-support/bin/check_banned_imports.sh -if git diff master --name-only | grep '\.rs$' > /dev/null; then - echo "* Checking formatting of rust files" && ./build-support/bin/check_rust_formatting.sh || exit 1 - # Clippy happens on a different shard because of separate caching concerns. - if [[ "${RUNNING_VIA_TRAVIS_CI_SCRIPT}" != "1" ]]; then - echo "* Running cargo clippy" && ./build-support/bin/check_clippy.sh || exit 1 - fi - echo "* Checking rust target headers" && build-support/bin/check_rust_target_headers.sh || exit 1 -fi - echo "* Checking for bad shell patterns" && ./build-support/bin/check_shell.sh || exit 1 -$(git rev-parse --verify master > /dev/null 2>&1) -if [[ $? -eq 0 ]]; then +# When travis builds a tag, it does so in a shallow clone without master fetched, which +# fails in pants changed. +master_present=$(git rev-parse --verify master > /dev/null 2>&1 || echo "Nope!") +if [[ "$master_present" != "Nope!" ]]; then echo "* Checking imports" && ./build-support/bin/isort.sh || \ die "To fix import sort order, run \`\"$(pwd)/build-support/bin/isort.sh\" -f\`" + # TODO(CMLivingston) Make lint use `-q` option again after addressing proper workunit labeling: # https://github.com/pantsbuild/pants/issues/6633 # TODO: add a test case for this while including a pexrc file, as python checkstyle currently fails # quite often with a pexrc available. echo "* Checking lint" && ./pants --exclude-target-regexp='testprojects/.*' --changed-parent=master lint || exit 1 + + if git diff master --name-only | grep '\.rs$' > /dev/null; then + echo "* Checking formatting of rust files" && ./build-support/bin/check_rust_formatting.sh || exit 1 + # Clippy happens on a different shard because of separate caching concerns. + if [[ "${RUNNING_VIA_TRAVIS_CI_SCRIPT}" != "1" ]]; then + echo "* Running cargo clippy" && ./build-support/bin/check_clippy.sh || exit 1 + fi + echo "* Checking rust target headers" && build-support/bin/check_rust_target_headers.sh || exit 1 + fi + + if git diff master --name-only | grep build-support/travis > /dev/null; then + echo "* Checking .travis.yml generation" && \ + actual_travis_yml=$(<.travis.yml) && \ + expected_travis_yml=$(./pants --quiet run build-support/travis:generate_travis_yml) && \ + [ "${expected_travis_yml}" == "${actual_travis_yml}" ] || \ + die "Travis config generator changed but .travis.yml file not regenerated. See top of that file for instructions." + fi else - # When travis builds a tag, it does so in a shallow clone without master fetched, which - # fails in pants changed. echo "* Skipping import/lint checks in partial working copy." fi - -if git diff master --name-only | grep build-support/travis > /dev/null; then - echo "* Checking .travis.yml generation" && \ - actual_travis_yml=$(<.travis.yml) && \ - expected_travis_yml=$(./pants --quiet run build-support/travis:generate_travis_yml) && \ - [ "${expected_travis_yml}" == "${actual_travis_yml}" ] || \ - die "Travis config generator changed but .travis.yml file not regenerated. See top of that file for instructions." -fi From 263891fdd7a51634e1e032ec9429c762a3836fc6 Mon Sep 17 00:00:00 2001 From: Stu Hood Date: Mon, 4 Feb 2019 17:48:28 -0800 Subject: [PATCH 2/2] Review feedback --- build-support/bin/pre-commit.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/build-support/bin/pre-commit.sh b/build-support/bin/pre-commit.sh index 384c1f14dda..3981f3bbdb6 100755 --- a/build-support/bin/pre-commit.sh +++ b/build-support/bin/pre-commit.sh @@ -55,8 +55,7 @@ echo "* Checking for bad shell patterns" && ./build-support/bin/check_shell.sh | # When travis builds a tag, it does so in a shallow clone without master fetched, which # fails in pants changed. -master_present=$(git rev-parse --verify master > /dev/null 2>&1 || echo "Nope!") -if [[ "$master_present" != "Nope!" ]]; then +if git rev-parse --verify "master" &>/dev/null; then echo "* Checking imports" && ./build-support/bin/isort.sh || \ die "To fix import sort order, run \`\"$(pwd)/build-support/bin/isort.sh\" -f\`"