Skip to content

Commit 65186e7

Browse files
committed
Add githooks
Add `githooks` directory and: - Copy the default pre-commit hook into new githooks directory - Add a call to clippy to the pre-commit hook - Add a section to the README instructing devs how to use the new githooks
1 parent 6d76bd4 commit 65186e7

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,17 @@ Contributions to this library are welcome. A few guidelines:
2222
* No crypto should be implemented in Rust, with the possible exception of hash functions. Cryptographic contributions should be directed upstream to libsecp256k1.
2323
* This library should always compile with any combination of features on **Rust 1.41.1**.
2424

25+
### Githooks
26+
27+
To assist devs in catching errors _before_ running CI we provide some githooks. If you do not
28+
already have locally configured githooks you can use the ones in this repository by running, in the
29+
root directory of the repository:
30+
```
31+
git config --local core.hooksPath githooks/
32+
```
33+
34+
Alternatively add symlinks in your `.git/hooks` directory to any of the githooks we provide.
35+
2536
## Fuzzing
2637

2738
If you want to fuzz this library, or any library which depends on it, you will

githooks/pre-commit

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

0 commit comments

Comments
 (0)