|
4 | 4 | # file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
5 | 5 |
|
6 | 6 | 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 | + |
7 | 40 | # Strip trailing / from directory path (in case it was added by autocomplete)
|
8 | 41 | DIR="${1%/}"
|
9 | 42 | COMMIT="$2"
|
@@ -79,18 +112,20 @@ if [ "$tree_actual_tree" != "$tree_commit" ]; then
|
79 | 112 | exit 1
|
80 | 113 | fi
|
81 | 114 |
|
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)" |
89 | 123 |
|
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 |
94 | 129 | fi
|
95 | 130 |
|
96 | 131 | echo "GOOD"
|
0 commit comments