git2-hooks wnaring fixes

and more clippy checks
This commit is contained in:
extrawurst 2024-02-23 18:01:26 +01:00 committed by extrawurst
parent e65d25da60
commit 11401872b5
3 changed files with 27 additions and 8 deletions

2
Cargo.lock generated
View File

@ -699,7 +699,7 @@ dependencies = [
[[package]]
name = "git2-hooks"
version = "0.3.1"
version = "0.3.2"
dependencies = [
"git2",
"git2-testing",

View File

@ -1,6 +1,6 @@
[package]
name = "git2-hooks"
version = "0.3.1"
version = "0.3.2"
authors = ["extrawurst <mail@rusticorn.com>"]
edition = "2021"
description = "adds git hooks support based on git2-rs"

View File

@ -8,6 +8,22 @@
//! most basic hook is: [`hooks_pre_commit`]. see also other `hooks_*` functions.
//!
//! [`create_hook`] is useful to create git hooks from code (unittest make heavy usage of it)
#![forbid(unsafe_code)]
#![deny(
unused_imports,
unused_must_use,
dead_code,
unstable_name_collisions,
unused_assignments
)]
#![deny(clippy::all, clippy::perf, clippy::pedantic, clippy::nursery)]
#![allow(
clippy::missing_errors_doc,
clippy::must_use_candidate,
clippy::module_name_repetitions
)]
mod error;
mod hookspath;
@ -15,7 +31,6 @@ use std::{
fs::File,
io::{Read, Write},
path::{Path, PathBuf},
process::Command,
};
pub use error::HooksError;
@ -56,17 +71,20 @@ pub enum HookResult {
impl HookResult {
/// helper to check if result is ok
pub fn is_ok(&self) -> bool {
matches!(self, HookResult::Ok { .. })
pub const fn is_ok(&self) -> bool {
matches!(self, Self::Ok { .. })
}
/// helper to check if result was run and not rejected
pub fn is_not_successful(&self) -> bool {
matches!(self, HookResult::RunNotSuccessful { .. })
pub const fn is_not_successful(&self) -> bool {
matches!(self, Self::RunNotSuccessful { .. })
}
}
/// helper method to create git hooks programmatically (heavy used in unittests)
///
/// # Panics
/// Panics if hook could not be created
pub fn create_hook(
r: &Repository,
hook: &str,
@ -86,7 +104,7 @@ fn create_hook_in_path(path: &Path, hook_script: &[u8]) {
#[cfg(unix)]
{
Command::new("chmod")
std::process::Command::new("chmod")
.arg("+x")
.arg(path)
// .current_dir(path)
@ -163,6 +181,7 @@ pub enum PrepareCommitMsgSource {
}
/// this hook is documented here <https://git-scm.com/docs/githooks#_prepare_commit_msg>
#[allow(clippy::needless_pass_by_value)]
pub fn hooks_prepare_commit_msg(
repo: &Repository,
other_paths: Option<&[&str]>,