Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only run master-dependent commithooks on master #7214

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 21 additions & 21 deletions build-support/bin/pre-commit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -51,36 +51,36 @@ 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.
if git rev-parse --verify "master" &>/dev/null; then
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if git rev-parse --verify "master" &>/dev/null; then
# Test if the "master" branch exists in the current git checkout.
if git rev-parse --verify "master" &>/dev/null; then

Copy link
Sponsor Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In order to unbreak the branch without another CI run, I'm going to land as is. Thank you for your attention to detail here though.

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