8
8
//! most basic hook is: [`hooks_pre_commit`]. see also other `hooks_*` functions.
9
9
//!
10
10
//! [`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
+
11
27
mod error;
12
28
mod hookspath;
13
29
14
30
use std:: {
15
31
fs:: File ,
16
32
io:: { Read , Write } ,
17
33
path:: { Path , PathBuf } ,
18
- process:: Command ,
19
34
} ;
20
35
21
36
pub use error:: HooksError ;
@@ -56,17 +71,20 @@ pub enum HookResult {
56
71
57
72
impl HookResult {
58
73
/// 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 { .. } )
61
76
}
62
77
63
78
/// 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 { .. } )
66
81
}
67
82
}
68
83
69
84
/// helper method to create git hooks programmatically (heavy used in unittests)
85
+ ///
86
+ /// # Panics
87
+ /// Panics if hook could not be created
70
88
pub fn create_hook (
71
89
r : & Repository ,
72
90
hook : & str ,
@@ -86,7 +104,7 @@ fn create_hook_in_path(path: &Path, hook_script: &[u8]) {
86
104
87
105
#[ cfg( unix) ]
88
106
{
89
- Command :: new ( "chmod" )
107
+ std :: process :: Command :: new ( "chmod" )
90
108
. arg ( "+x" )
91
109
. arg ( path)
92
110
// .current_dir(path)
@@ -163,6 +181,7 @@ pub enum PrepareCommitMsgSource {
163
181
}
164
182
165
183
/// this hook is documented here <https://git-scm.com/docs/githooks#_prepare_commit_msg>
184
+ #[ allow( clippy:: needless_pass_by_value) ]
166
185
pub fn hooks_prepare_commit_msg (
167
186
repo : & Repository ,
168
187
other_paths : Option < & [ & str ] > ,
0 commit comments