@@ -103,6 +103,19 @@ mod tests {
103
103
assert_eq ! ( res, HookResult :: Ok ) ;
104
104
}
105
105
106
+ fn create_hook ( path : & Path , hook_path : & str , hook_script : & [ u8 ] ) {
107
+ File :: create ( & path. join ( hook_path) )
108
+ . unwrap ( )
109
+ . write_all ( hook_script)
110
+ . unwrap ( ) ;
111
+
112
+ Command :: new ( "chmod" )
113
+ . args ( & [ "+x" , hook_path] )
114
+ . current_dir ( path)
115
+ . output ( )
116
+ . unwrap ( ) ;
117
+ }
118
+
106
119
#[ test]
107
120
#[ cfg( not( windows) ) ]
108
121
fn test_hooks_commit_msg_ok ( ) {
@@ -115,16 +128,7 @@ mod tests {
115
128
exit 0
116
129
" ;
117
130
118
- File :: create ( & root. join ( HOOK_COMMIT_MSG ) )
119
- . unwrap ( )
120
- . write_all ( hook)
121
- . unwrap ( ) ;
122
-
123
- Command :: new ( "chmod" )
124
- . args ( & [ "+x" , HOOK_COMMIT_MSG ] )
125
- . current_dir ( root)
126
- . output ( )
127
- . unwrap ( ) ;
131
+ create_hook ( root, HOOK_COMMIT_MSG , hook) ;
128
132
129
133
let mut msg = String :: from ( "test" ) ;
130
134
let res = hooks_commit_msg ( repo_path, & mut msg) ;
@@ -148,16 +152,7 @@ echo 'rejected'
148
152
exit 1
149
153
" ;
150
154
151
- File :: create ( & root. join ( HOOK_COMMIT_MSG ) )
152
- . unwrap ( )
153
- . write_all ( hook)
154
- . unwrap ( ) ;
155
-
156
- Command :: new ( "chmod" )
157
- . args ( & [ "+x" , HOOK_COMMIT_MSG ] )
158
- . current_dir ( root)
159
- . output ( )
160
- . unwrap ( ) ;
155
+ create_hook ( root, HOOK_COMMIT_MSG , hook) ;
161
156
162
157
let mut msg = String :: from ( "test" ) ;
163
158
let res = hooks_commit_msg ( repo_path, & mut msg) ;
@@ -183,16 +178,7 @@ echo 'msg' > $1
183
178
exit 0
184
179
" ;
185
180
186
- File :: create ( & root. join ( HOOK_COMMIT_MSG ) )
187
- . unwrap ( )
188
- . write_all ( hook)
189
- . unwrap ( ) ;
190
-
191
- Command :: new ( "chmod" )
192
- . args ( & [ "+x" , HOOK_COMMIT_MSG ] )
193
- . current_dir ( root)
194
- . output ( )
195
- . unwrap ( ) ;
181
+ create_hook ( root, HOOK_COMMIT_MSG , hook) ;
196
182
197
183
let mut msg = String :: from ( "test" ) ;
198
184
let res = hooks_commit_msg ( repo_path, & mut msg) ;
0 commit comments