forked from bitcoin/bitcoin
-
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.
[Travis] Add separate job to check doc/logprint/subtree
Break out a new job to do the basic linting that check-dock.py and logprint-scanner.py did. Also add new scripts to check the sanity of any git subtrees and to check that new pull requests don't contain any trailing whitespace. Also, remove the outdated slack notification callback
- Loading branch information
Showing
3 changed files
with
235 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
#!/bin/sh | ||
# Copyright (c) 2015 The Bitcoin Core developers | ||
# Distributed under the MIT software license, see the accompanying | ||
# file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||
|
||
export LC_ALL=C | ||
DIR="$1" | ||
COMMIT="$2" | ||
if [ -z "$COMMIT" ]; then | ||
COMMIT=HEAD | ||
fi | ||
|
||
# Taken from git-subtree (Copyright (C) 2009 Avery Pennarun <[email protected]>) | ||
find_latest_squash() | ||
{ | ||
dir="$1" | ||
sq= | ||
main= | ||
sub= | ||
git log --grep="^git-subtree-dir: $dir/*\$" \ | ||
--pretty=format:'START %H%n%s%n%n%b%nEND%n' "$COMMIT" | | ||
while read a b _; do | ||
case "$a" in | ||
START) sq="$b" ;; | ||
git-subtree-mainline:) main="$b" ;; | ||
git-subtree-split:) sub="$b" ;; | ||
END) | ||
if [ -n "$sub" ]; then | ||
if [ -n "$main" ]; then | ||
# a rejoin commit? | ||
# Pretend its sub was a squash. | ||
sq="$sub" | ||
fi | ||
echo "$sq" "$sub" | ||
break | ||
fi | ||
sq= | ||
main= | ||
sub= | ||
;; | ||
esac | ||
done | ||
} | ||
|
||
# find latest subtree update | ||
latest_squash="$(find_latest_squash "$DIR")" | ||
if [ -z "$latest_squash" ]; then | ||
echo "ERROR: $DIR is not a subtree" >&2 | ||
exit 2 | ||
fi | ||
set $latest_squash | ||
old=$1 | ||
rev=$2 | ||
|
||
# get the tree in the current commit | ||
tree_actual=$(git ls-tree -d "$COMMIT" "$DIR" | head -n 1) | ||
if [ -z "$tree_actual" ]; then | ||
echo "FAIL: subtree directory $DIR not found in $COMMIT" >&2 | ||
exit 1 | ||
fi | ||
set $tree_actual | ||
tree_actual_type=$2 | ||
tree_actual_tree=$3 | ||
echo "$DIR in $COMMIT currently refers to $tree_actual_type $tree_actual_tree" | ||
if [ "d$tree_actual_type" != "dtree" ]; then | ||
echo "FAIL: subtree directory $DIR is not a tree in $COMMIT" >&2 | ||
exit 1 | ||
fi | ||
|
||
# get the tree at the time of the last subtree update | ||
tree_commit=$(git show -s --format="%T" $old) | ||
echo "$DIR in $COMMIT was last updated in commit $old (tree $tree_commit)" | ||
|
||
# ... and compare the actual tree with it | ||
if [ "$tree_actual_tree" != "$tree_commit" ]; then | ||
git diff $tree_commit $tree_actual_tree >&2 | ||
echo "FAIL: subtree directory was touched without subtree merge" >&2 | ||
exit 1 | ||
fi | ||
|
||
# get the tree in the subtree commit referred to | ||
if [ "d$(git cat-file -t $rev 2>/dev/null)" != dcommit ]; then | ||
echo "subtree commit $rev unavailable: cannot compare" >&2 | ||
exit | ||
fi | ||
tree_subtree=$(git show -s --format="%T" $rev) | ||
echo "$DIR in $COMMIT was last updated to upstream commit $rev (tree $tree_subtree)" | ||
|
||
# ... and compare the actual tree with it | ||
if [ "$tree_actual_tree" != "$tree_subtree" ]; then | ||
echo "FAIL: subtree update commit differs from upstream tree!" >&2 | ||
exit 1 | ||
fi | ||
|
||
echo "GOOD" |
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,113 @@ | ||
#!/bin/bash | ||
# | ||
# Copyright (c) 2017 The Bitcoin Core developers | ||
# Distributed under the MIT software license, see the accompanying | ||
# file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||
# | ||
# Check for new lines in diff that introduce trailing whitespace. | ||
|
||
# We can't run this check unless we know the commit range for the PR. | ||
|
||
export LC_ALL=C | ||
while getopts "?" opt; do | ||
case $opt in | ||
?) | ||
echo "Usage: .lint-whitespace.sh [N]" | ||
echo " TRAVIS_COMMIT_RANGE='<commit range>' .lint-whitespace.sh" | ||
echo " .lint-whitespace.sh -?" | ||
echo "Checks unstaged changes, the previous N commits, or a commit range." | ||
echo "TRAVIS_COMMIT_RANGE='47ba2c3...ee50c9e' .lint-whitespace.sh" | ||
exit 0 | ||
;; | ||
esac | ||
done | ||
|
||
if [ -z "${TRAVIS_COMMIT_RANGE}" ]; then | ||
if [ "$1" ]; then | ||
TRAVIS_COMMIT_RANGE="HEAD~$1...HEAD" | ||
else | ||
TRAVIS_COMMIT_RANGE="HEAD" | ||
fi | ||
fi | ||
|
||
showdiff() { | ||
if ! git diff -U0 "${TRAVIS_COMMIT_RANGE}" -- "." ":(exclude)depends/patches/" ":(exclude)src/leveldb/" ":(exclude)src/secp256k1/" ":(exclude)src/univalue/" ":(exclude)doc/release-notes/"; then | ||
echo "Failed to get a diff" | ||
exit 1 | ||
fi | ||
} | ||
|
||
showcodediff() { | ||
if ! git diff -U0 "${TRAVIS_COMMIT_RANGE}" -- *.cpp *.h *.md *.py *.sh ":(exclude)src/leveldb/" ":(exclude)src/secp256k1/" ":(exclude)src/univalue/" ":(exclude)doc/release-notes/"; then | ||
echo "Failed to get a diff" | ||
exit 1 | ||
fi | ||
} | ||
|
||
RET=0 | ||
|
||
# Check if trailing whitespace was found in the diff. | ||
if showdiff | grep -E -q '^\+.*\s+$'; then | ||
echo "This diff appears to have added new lines with trailing whitespace." | ||
echo "The following changes were suspected:" | ||
FILENAME="" | ||
SEEN=0 | ||
SEENLN=0 | ||
while read -r line; do | ||
if [[ "$line" =~ ^diff ]]; then | ||
FILENAME="$line" | ||
SEEN=0 | ||
elif [[ "$line" =~ ^@@ ]]; then | ||
LINENUMBER="$line" | ||
SEENLN=0 | ||
else | ||
if [ "$SEEN" -eq 0 ]; then | ||
# The first time a file is seen with trailing whitespace, we print the | ||
# filename (preceded by a newline). | ||
echo | ||
echo "$FILENAME" | ||
SEEN=1 | ||
fi | ||
if [ "$SEENLN" -eq 0 ]; then | ||
echo "$LINENUMBER" | ||
SEENLN=1 | ||
fi | ||
echo "$line" | ||
fi | ||
done < <(showdiff | grep -E '^(diff --git |@@|\+.*\s+$)') | ||
RET=1 | ||
fi | ||
|
||
# Check if tab characters were found in the diff. | ||
if showcodediff | perl -nle '$MATCH++ if m{^\+.*\t}; END{exit 1 unless $MATCH>0}' > /dev/null; then | ||
echo "This diff appears to have added new lines with tab characters instead of spaces." | ||
echo "The following changes were suspected:" | ||
FILENAME="" | ||
SEEN=0 | ||
SEENLN=0 | ||
while read -r line; do | ||
if [[ "$line" =~ ^diff ]]; then | ||
FILENAME="$line" | ||
SEEN=0 | ||
elif [[ "$line" =~ ^@@ ]]; then | ||
LINENUMBER="$line" | ||
SEENLN=0 | ||
else | ||
if [ "$SEEN" -eq 0 ]; then | ||
# The first time a file is seen with a tab character, we print the | ||
# filename (preceded by a newline). | ||
echo | ||
echo "$FILENAME" | ||
SEEN=1 | ||
fi | ||
if [ "$SEENLN" -eq 0 ]; then | ||
echo "$LINENUMBER" | ||
SEENLN=1 | ||
fi | ||
echo "$line" | ||
fi | ||
done < <(showcodediff | perl -nle 'print if m{^(diff --git |@@|\+.*\t)}') | ||
RET=1 | ||
fi | ||
|
||
exit $RET |