File tree Expand file tree Collapse file tree 1 file changed +37
-8
lines changed Expand file tree Collapse file tree 1 file changed +37
-8
lines changed Original file line number Diff line number Diff line change @@ -26,14 +26,12 @@ pub fn hooks_commit_msg(
26
26
27
27
let res = run_hook ( repo_path, HOOK_COMMIT_MSG , & [ & file_path] ) ;
28
28
29
- if let HookResult :: NotOk ( e) = res {
30
- let mut file = file. reopen ( ) . unwrap ( ) ;
31
- msg. clear ( ) ;
32
- file. read_to_string ( msg) . unwrap ( ) ;
33
- HookResult :: NotOk ( e)
34
- } else {
35
- HookResult :: Ok
36
- }
29
+ // load possibly altered msg
30
+ let mut file = file. reopen ( ) . unwrap ( ) ;
31
+ msg. clear ( ) ;
32
+ file. read_to_string ( msg) . unwrap ( ) ;
33
+
34
+ res
37
35
} else {
38
36
HookResult :: Ok
39
37
}
@@ -171,4 +169,35 @@ exit 1
171
169
172
170
assert_eq ! ( msg, String :: from( "msg\n " ) ) ;
173
171
}
172
+
173
+ #[ test]
174
+ #[ cfg( not( windows) ) ]
175
+ fn test_commit_msg_no_block_but_alter ( ) {
176
+ let ( _td, repo) = repo_init ( ) ;
177
+ let root = repo. path ( ) . parent ( ) . unwrap ( ) ;
178
+ let repo_path = root. as_os_str ( ) . to_str ( ) . unwrap ( ) ;
179
+
180
+ let hook = b"
181
+ #!/bin/sh
182
+ echo 'msg' > $1
183
+ exit 0
184
+ " ;
185
+
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 ( ) ;
196
+
197
+ let mut msg = String :: from ( "test" ) ;
198
+ let res = hooks_commit_msg ( repo_path, & mut msg) ;
199
+
200
+ assert_eq ! ( res, HookResult :: Ok ) ;
201
+ assert_eq ! ( msg, String :: from( "msg\n " ) ) ;
202
+ }
174
203
}
You can’t perform that action at this time.
0 commit comments