mirror of
https://github.com/gitui-org/gitui
synced 2026-05-24 09:28:21 +00:00
support altering commit-msg on ok hook
This commit is contained in:
parent
f144d97e0c
commit
b9ac1865db
1 changed files with 37 additions and 8 deletions
|
|
@ -26,14 +26,12 @@ pub fn hooks_commit_msg(
|
||||||
|
|
||||||
let res = run_hook(repo_path, HOOK_COMMIT_MSG, &[&file_path]);
|
let res = run_hook(repo_path, HOOK_COMMIT_MSG, &[&file_path]);
|
||||||
|
|
||||||
if let HookResult::NotOk(e) = res {
|
// load possibly altered msg
|
||||||
let mut file = file.reopen().unwrap();
|
let mut file = file.reopen().unwrap();
|
||||||
msg.clear();
|
msg.clear();
|
||||||
file.read_to_string(msg).unwrap();
|
file.read_to_string(msg).unwrap();
|
||||||
HookResult::NotOk(e)
|
|
||||||
} else {
|
res
|
||||||
HookResult::Ok
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
HookResult::Ok
|
HookResult::Ok
|
||||||
}
|
}
|
||||||
|
|
@ -171,4 +169,35 @@ exit 1
|
||||||
|
|
||||||
assert_eq!(msg, String::from("msg\n"));
|
assert_eq!(msg, String::from("msg\n"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[cfg(not(windows))]
|
||||||
|
fn test_commit_msg_no_block_but_alter() {
|
||||||
|
let (_td, repo) = repo_init();
|
||||||
|
let root = repo.path().parent().unwrap();
|
||||||
|
let repo_path = root.as_os_str().to_str().unwrap();
|
||||||
|
|
||||||
|
let hook = b"
|
||||||
|
#!/bin/sh
|
||||||
|
echo 'msg' > $1
|
||||||
|
exit 0
|
||||||
|
";
|
||||||
|
|
||||||
|
File::create(&root.join(HOOK_COMMIT_MSG))
|
||||||
|
.unwrap()
|
||||||
|
.write_all(hook)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
Command::new("chmod")
|
||||||
|
.args(&["+x", HOOK_COMMIT_MSG])
|
||||||
|
.current_dir(root)
|
||||||
|
.output()
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
let mut msg = String::from("test");
|
||||||
|
let res = hooks_commit_msg(repo_path, &mut msg);
|
||||||
|
|
||||||
|
assert_eq!(res, HookResult::Ok);
|
||||||
|
assert_eq!(msg, String::from("msg\n"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue