Skip to content

Commit 1140187

Browse files
committed
git2-hooks wnaring fixes
and more clippy checks
1 parent e65d25d commit 1140187

File tree

3 files changed

+27
-8
lines changed

3 files changed

+27
-8
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

git2-hooks/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "git2-hooks"
3-
version = "0.3.1"
3+
version = "0.3.2"
44
authors = ["extrawurst <[email protected]>"]
55
edition = "2021"
66
description = "adds git hooks support based on git2-rs"

git2-hooks/src/lib.rs

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,29 @@
88
//! most basic hook is: [`hooks_pre_commit`]. see also other `hooks_*` functions.
99
//!
1010
//! [`create_hook`] is useful to create git hooks from code (unittest make heavy usage of it)
11+
12+
#![forbid(unsafe_code)]
13+
#![deny(
14+
unused_imports,
15+
unused_must_use,
16+
dead_code,
17+
unstable_name_collisions,
18+
unused_assignments
19+
)]
20+
#![deny(clippy::all, clippy::perf, clippy::pedantic, clippy::nursery)]
21+
#![allow(
22+
clippy::missing_errors_doc,
23+
clippy::must_use_candidate,
24+
clippy::module_name_repetitions
25+
)]
26+
1127
mod error;
1228
mod hookspath;
1329

1430
use std::{
1531
fs::File,
1632
io::{Read, Write},
1733
path::{Path, PathBuf},
18-
process::Command,
1934
};
2035

2136
pub use error::HooksError;
@@ -56,17 +71,20 @@ pub enum HookResult {
5671

5772
impl HookResult {
5873
/// helper to check if result is ok
59-
pub fn is_ok(&self) -> bool {
60-
matches!(self, HookResult::Ok { .. })
74+
pub const fn is_ok(&self) -> bool {
75+
matches!(self, Self::Ok { .. })
6176
}
6277

6378
/// helper to check if result was run and not rejected
64-
pub fn is_not_successful(&self) -> bool {
65-
matches!(self, HookResult::RunNotSuccessful { .. })
79+
pub const fn is_not_successful(&self) -> bool {
80+
matches!(self, Self::RunNotSuccessful { .. })
6681
}
6782
}
6883

6984
/// helper method to create git hooks programmatically (heavy used in unittests)
85+
///
86+
/// # Panics
87+
/// Panics if hook could not be created
7088
pub fn create_hook(
7189
r: &Repository,
7290
hook: &str,
@@ -86,7 +104,7 @@ fn create_hook_in_path(path: &Path, hook_script: &[u8]) {
86104

87105
#[cfg(unix)]
88106
{
89-
Command::new("chmod")
107+
std::process::Command::new("chmod")
90108
.arg("+x")
91109
.arg(path)
92110
// .current_dir(path)
@@ -163,6 +181,7 @@ pub enum PrepareCommitMsgSource {
163181
}
164182

165183
/// this hook is documented here <https://git-scm.com/docs/githooks#_prepare_commit_msg>
184+
#[allow(clippy::needless_pass_by_value)]
166185
pub fn hooks_prepare_commit_msg(
167186
repo: &Repository,
168187
other_paths: Option<&[&str]>,

0 commit comments

Comments
 (0)