Skip to content

Commit

Permalink
Add a simple pre-commit git hook to verify formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
jessebraham committed Jun 7, 2023
1 parent 36804b0 commit 0628b75
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@ A library and command-line tool for flashing Espressif devices.

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

## Git Hooks

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:

```bash
$ cp pre-commit .git/hooks/pre-commit
```

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.

## License

Licensed under either of:
Expand Down
11 changes: 11 additions & 0 deletions pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env bash

# Exit immediately on first non-zero status from a command in the script.
set -o errexit

# Ensure all tools being used are available.
command -v "cargo" >/dev/null 2>&1 || { echo >&2 "The 'cargo' command is not installed, exiting"; exit 1; }
command -v "rustfmt" >/dev/null 2>&1 || { echo >&2 "The 'rustfmt' command is not installed, exiting"; exit 1; }

# Check the formatting of all Rust code in the workspace.
cargo fmt --all -- --check

0 comments on commit 0628b75

Please sign in to comment.