Skip to content

Commit e20b488

Browse files
committed
Merge #20567: test: Add option to git-subtree-check to do full check, add help
34c80d9 test: Add option to git-subtree-check to do full check, add help (Wladimir J. van der Laan) Pull request description: This adds a brief help text to `git-subtree-check.sh` and adds an option to do a full remote check instead of having two different code paths with a successful exit status. Also make it explicit that the CI is not doing this. ACKs for top commit: fjahr: tested ACK 34c80d9 Tree-SHA512: 20f672fd3b3c1d633eccf9998fdd738194cdd7d10cc206691f2dcc28bbbf8187b8d06b87814f875a06145b179f5ca1f4f4f9922972be72759cf5ac6e0c11abd1
2 parents dcff2ee + 34c80d9 commit e20b488

File tree

3 files changed

+58
-16
lines changed

3 files changed

+58
-16
lines changed

ci/lint/06_script.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ if [ "$TRAVIS_EVENT_TYPE" = "pull_request" ]; then
1414
test/lint/commit-script-check.sh $COMMIT_RANGE
1515
fi
1616

17+
# This only checks that the trees are pure subtrees, it is not doing a full
18+
# check with -r to not have to fetch all the remotes.
1719
test/lint/git-subtree-check.sh src/crypto/ctaes
1820
test/lint/git-subtree-check.sh src/secp256k1
1921
test/lint/git-subtree-check.sh src/univalue

test/lint/README.md

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,16 @@ git-subtree-check.sh
1515
Run this script from the root of the repository to verify that a subtree matches the contents of
1616
the commit it claims to have been updated to.
1717

18-
To use, make sure that you have fetched the upstream repository branch in which the subtree is
18+
```
19+
Usage: test/lint/git-subtree-check.sh [-r] DIR [COMMIT]
20+
test/lint/git-subtree-check.sh -?
21+
```
22+
23+
- `DIR` is the prefix within the repository to check.
24+
- `COMMIT` is the commit to check, if it is not provided, HEAD will be used.
25+
- `-r` checks that subtree commit is present in repository.
26+
27+
To do a full check with `-r`, make sure that you have fetched the upstream repository branch in which the subtree is
1928
maintained:
2029
* for `src/secp256k1`: https://github.com/bitcoin-core/secp256k1.git (branch master)
2130
* for `src/leveldb`: https://github.com/bitcoin-core/leveldb.git (branch bitcoin-fork)
@@ -29,10 +38,6 @@ To do so, add the upstream repository as remote:
2938
git remote add --fetch secp256k1 https://github.com/bitcoin-core/secp256k1.git
3039
```
3140

32-
Usage: `git-subtree-check.sh DIR (COMMIT)`
33-
34-
`COMMIT` may be omitted, in which case `HEAD` is used.
35-
3641
lint-all.sh
3742
===========
3843
Calls other scripts with the `lint-` prefix.

test/lint/git-subtree-check.sh

Lines changed: 46 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,39 @@
44
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
55

66
export LC_ALL=C
7+
8+
check_remote=0
9+
while getopts "?hr" opt; do
10+
case $opt in
11+
'?' | h)
12+
echo "Usage: $0 [-r] DIR [COMMIT]"
13+
echo " $0 -?"
14+
echo ""
15+
echo "Checks that a certain prefix is pure subtree, and optionally whether the"
16+
echo "referenced commit is present in any fetched remote."
17+
echo ""
18+
echo "DIR is the prefix within the repository to check."
19+
echo "COMMIT is the commit to check, if it is not provided, HEAD will be used."
20+
echo ""
21+
echo "-r Check that subtree commit is present in repository."
22+
echo " To do this check, fetch the subtreed remote first. Example:"
23+
echo ""
24+
echo " git fetch https://github.com/bitcoin-core/secp256k1.git"
25+
echo " test/lint/git-subtree-check.sh -r src/secp256k1"
26+
exit 1
27+
;;
28+
r)
29+
check_remote=1
30+
;;
31+
esac
32+
done
33+
shift $((OPTIND-1))
34+
35+
if [ -z "$1" ]; then
36+
echo "Need to provide a DIR, see $0 -?"
37+
exit 1
38+
fi
39+
740
# Strip trailing / from directory path (in case it was added by autocomplete)
841
DIR="${1%/}"
942
COMMIT="$2"
@@ -79,18 +112,20 @@ if [ "$tree_actual_tree" != "$tree_commit" ]; then
79112
exit 1
80113
fi
81114

82-
# get the tree in the subtree commit referred to
83-
if [ "d$(git cat-file -t $rev 2>/dev/null)" != dcommit ]; then
84-
echo "subtree commit $rev unavailable: cannot compare. Did you add and fetch the remote?" >&2
85-
exit
86-
fi
87-
tree_subtree=$(git show -s --format="%T" $rev)
88-
echo "$DIR in $COMMIT was last updated to upstream commit $rev (tree $tree_subtree)"
115+
if [ "$check_remote" != "0" ]; then
116+
# get the tree in the subtree commit referred to
117+
if [ "d$(git cat-file -t $rev 2>/dev/null)" != dcommit ]; then
118+
echo "subtree commit $rev unavailable: cannot compare. Did you add and fetch the remote?" >&2
119+
exit 1
120+
fi
121+
tree_subtree=$(git show -s --format="%T" $rev)
122+
echo "$DIR in $COMMIT was last updated to upstream commit $rev (tree $tree_subtree)"
89123

90-
# ... and compare the actual tree with it
91-
if [ "$tree_actual_tree" != "$tree_subtree" ]; then
92-
echo "FAIL: subtree update commit differs from upstream tree!" >&2
93-
exit 1
124+
# ... and compare the actual tree with it
125+
if [ "$tree_actual_tree" != "$tree_subtree" ]; then
126+
echo "FAIL: subtree update commit differs from upstream tree!" >&2
127+
exit 1
128+
fi
94129
fi
95130

96131
echo "GOOD"

0 commit comments

Comments
 (0)