Skip to content

Commit d2d6906

Browse files
author
Stephan Dilly
committed
cleanup
1 parent b9ac186 commit d2d6906

File tree

1 file changed

+16
-30
lines changed

1 file changed

+16
-30
lines changed

asyncgit/src/sync/hooks.rs

Lines changed: 16 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,19 @@ mod tests {
103103
assert_eq!(res, HookResult::Ok);
104104
}
105105

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+
106119
#[test]
107120
#[cfg(not(windows))]
108121
fn test_hooks_commit_msg_ok() {
@@ -115,16 +128,7 @@ mod tests {
115128
exit 0
116129
";
117130

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);
128132

129133
let mut msg = String::from("test");
130134
let res = hooks_commit_msg(repo_path, &mut msg);
@@ -148,16 +152,7 @@ echo 'rejected'
148152
exit 1
149153
";
150154

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);
161156

162157
let mut msg = String::from("test");
163158
let res = hooks_commit_msg(repo_path, &mut msg);
@@ -183,16 +178,7 @@ echo 'msg' > $1
183178
exit 0
184179
";
185180

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);
196182

197183
let mut msg = String::from("test");
198184
let res = hooks_commit_msg(repo_path, &mut msg);

0 commit comments

Comments
 (0)