-
Notifications
You must be signed in to change notification settings - Fork 382
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
787: Add utility to install git hooks. r=Emilgardis a=Alexhuszagh Adds the `install-git-hooks` to `cross-dev`, which installs pre-commit hooks to ensure clippy and fmt are run on all commits. Co-authored-by: Alex Huszagh <[email protected]>
- Loading branch information
Showing
4 changed files
with
43 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
use clap::Args; | ||
|
||
use std::path::Path; | ||
|
||
#[derive(Args, Debug)] | ||
pub struct InstallGitHooks { | ||
/// Provide verbose diagnostic output. | ||
#[clap(short, long)] | ||
verbose: bool, | ||
} | ||
|
||
pub fn install_git_hooks(InstallGitHooks { verbose }: InstallGitHooks) -> cross::Result<()> { | ||
let metadata = cross::cargo_metadata_with_args( | ||
Some(Path::new(env!("CARGO_MANIFEST_DIR"))), | ||
None, | ||
verbose, | ||
)? | ||
.ok_or_else(|| eyre::eyre!("could not find cross workspace"))?; | ||
let git_hooks = metadata.workspace_root.join(".git").join("hooks"); | ||
let cross_dev = metadata.workspace_root.join("xtask").join("src"); | ||
std::fs::copy(cross_dev.join("pre-commit"), git_hooks.join("pre-commit"))?; | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#!/usr/bin/env bash | ||
|
||
echo "Running rustfmt and clippy checks." | ||
|
||
set -ex | ||
|
||
flags=(--all-features --all-targets --workspace) | ||
cargo fmt -- --check | ||
cargo clippy "${flags[@]}" -- --deny warnings | ||
if cargo +nightly >/dev/null 2>&1; then | ||
cargo +nightly clippy "${flags[@]}" -- --deny warnings | ||
fi |