Skip to content

Commit 0628b75

Browse files
committed
Add a simple pre-commit git hook to verify formatting
1 parent 36804b0 commit 0628b75

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

README.md

+10
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,16 @@ A library and command-line tool for flashing Espressif devices.
2020

2121
For more information and installation instructions, please refer to the `espflash` package's [README](./espflash/README.md).
2222

23+
## Git Hooks
24+
25+
We provide a simple `pre-commit` hook to verify the formatting of each package prior to committing changes. This can be enabled by placing it in the `.git/hooks/` directory:
26+
27+
```bash
28+
$ cp pre-commit .git/hooks/pre-commit
29+
```
30+
31+
When using this hook, you can choose to ignore its failure on a per-commit basis by committing with the `--no-verify` flag; however, you will need to be sure that all packages are formatted when submitting a pull request.
32+
2333
## License
2434

2535
Licensed under either of:

pre-commit

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/usr/bin/env bash
2+
3+
# Exit immediately on first non-zero status from a command in the script.
4+
set -o errexit
5+
6+
# Ensure all tools being used are available.
7+
command -v "cargo" >/dev/null 2>&1 || { echo >&2 "The 'cargo' command is not installed, exiting"; exit 1; }
8+
command -v "rustfmt" >/dev/null 2>&1 || { echo >&2 "The 'rustfmt' command is not installed, exiting"; exit 1; }
9+
10+
# Check the formatting of all Rust code in the workspace.
11+
cargo fmt --all -- --check

0 commit comments

Comments
 (0)