Skip to content

Commit 01f594e

Browse files
committed
Merge #56: Add githooks
f8c7e35 Add --all-features when running clippy in ci (Tobin C. Harding) cfbfc7e Add git pre-commit hook (Tobin C. Harding) Pull request description: Add a pre-commit git hook as we did in `rust-bitcoin`. Patch 2 adds `--all-features` to the clippy CI run, this is just future proofing, no effect on the current code. ACKs for top commit: apoelstra: ACK f8c7e35 Tree-SHA512: 1fc23921fdfdd097b436d62bf84d947e46297a27dd10c7477f5c9f29a7dfd8129bc8e0d294b016de649d368298228946681ac82cba6a71089fe1e999d55e672a
2 parents eb3049e + f8c7e35 commit 01f594e

File tree

3 files changed

+65
-1
lines changed

3 files changed

+65
-1
lines changed

.github/workflows/rust.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ jobs:
103103
- uses: actions-rs/cargo@v1
104104
with:
105105
command: clippy
106-
args: --all-targets -- -D warnings
106+
args: --all-targets --all-features -- -D warnings
107107

108108
Fmt:
109109
name: Fmt

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,18 @@ git subtree pull --prefix='depend/bitcoin' git@github.com:bitcoin/bitcoin.git v0
4545
The MSRV of this crate is **1.41.1**.
4646

4747

48+
## Githooks
49+
50+
To assist devs in catching errors _before_ running CI we provide some githooks. If you do not
51+
already have locally configured githooks you can use the ones in this repository by running, in the
52+
root directory of the repository:
53+
```
54+
git config --local core.hooksPath githooks/
55+
```
56+
57+
Alternatively add symlinks in your `.git/hooks` directory to any of the githooks we provide.
58+
59+
4860
## API
4961

5062
The API is very basic, exposing Bitcoin's API as is.

githooks/pre-commit

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#!/bin/sh
2+
#
3+
# Verify what is about to be committed. Called by "git commit" with no
4+
# arguments. The hook should exit with non-zero status after issuing an
5+
# appropriate message if it wants to stop the commit.
6+
7+
if git rev-parse --verify HEAD >/dev/null 2>&1
8+
then
9+
against=HEAD
10+
else
11+
# Initial commit: diff against an empty tree object
12+
against=$(git hash-object -t tree /dev/null)
13+
fi
14+
15+
# If you want to allow non-ASCII filenames set this variable to true.
16+
allownonascii=$(git config --bool hooks.allownonascii)
17+
18+
# Redirect output to stderr.
19+
exec 1>&2
20+
21+
# Cross platform projects tend to avoid non-ASCII filenames; prevent
22+
# them from being added to the repository. We exploit the fact that the
23+
# printable range starts at the space character and ends with tilde.
24+
if [ "$allownonascii" != "true" ] &&
25+
# Note that the use of brackets around a tr range is ok here, (it's
26+
# even required, for portability to Solaris 10's /usr/bin/tr), since
27+
# the square bracket bytes happen to fall in the designated range.
28+
test $(git diff --cached --name-only --diff-filter=A -z $against |
29+
LC_ALL=C tr -d '[ -~]\0' | wc -c) != 0
30+
then
31+
cat <<\EOF
32+
Error: Attempt to add a non-ASCII file name.
33+
34+
This can cause problems if you want to work with people on other platforms.
35+
36+
To be portable it is advisable to rename the file.
37+
38+
If you know what you are doing you can disable this check using:
39+
40+
git config hooks.allownonascii true
41+
EOF
42+
exit 1
43+
fi
44+
45+
# If there are whitespace errors, print the offending file names and fail.
46+
git diff-index --check --cached $against -- || exit 1
47+
48+
# Check that code lints cleanly.
49+
cargo clippy --all-targets --all-features -- -D warnings || exit 1
50+
51+
# Check that there are no formatting issues.
52+
cargo +nightly fmt --check || exit 1

0 commit comments

Comments
 (0)