Skip to content

Commit b9ac186

Browse files
author
Stephan Dilly
committed
support altering commit-msg on ok hook
1 parent f144d97 commit b9ac186

File tree

1 file changed

+37
-8
lines changed

1 file changed

+37
-8
lines changed

asyncgit/src/sync/hooks.rs

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,12 @@ pub fn hooks_commit_msg(
2626

2727
let res = run_hook(repo_path, HOOK_COMMIT_MSG, &[&file_path]);
2828

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
3735
} else {
3836
HookResult::Ok
3937
}
@@ -171,4 +169,35 @@ exit 1
171169

172170
assert_eq!(msg, String::from("msg\n"));
173171
}
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+
}
174203
}

0 commit comments

Comments
 (0)