Skip to content

Commit bcee68a

Browse files
author
Naseschwarz
committed
Move git2_hooks::create_hook_in_path to git2-testing
This is a function that's solely used in testing and has no dependencies into git2_hooks and panics on common errors. It's a much better fit for git2-testing.
1 parent 3ede6b5 commit bcee68a

File tree

2 files changed

+21
-15
lines changed

2 files changed

+21
-15
lines changed

Diff for: git2-hooks/src/lib.rs

-15
Original file line numberDiff line numberDiff line change
@@ -97,21 +97,6 @@ pub fn create_hook(
9797

9898
path
9999
}
100-
101-
fn create_hook_in_path(path: &Path, hook_script: &[u8]) {
102-
File::create(path).unwrap().write_all(hook_script).unwrap();
103-
104-
#[cfg(unix)]
105-
{
106-
std::process::Command::new("chmod")
107-
.arg("+x")
108-
.arg(path)
109-
// .current_dir(path)
110-
.output()
111-
.unwrap();
112-
}
113-
}
114-
115100
/// Git hook: `commit_msg`
116101
///
117102
/// This hook is documented here <https://git-scm.com/docs/githooks#_commit_msg>.

Diff for: git2-testing/src/lib.rs

+21
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
use git2::Repository;
2+
use std::fs::File;
3+
use std::io::Write;
4+
use std::path::Path;
25
use tempfile::TempDir;
36

47
/// initialize test repo in temp path
@@ -83,3 +86,21 @@ fn sandbox_config_files() {
8386
set_search_path(ConfigLevel::ProgramData, path).unwrap();
8487
});
8588
}
89+
90+
/// helper method to create a git hook in a custom path (used in unittests)
91+
///
92+
/// # Panics
93+
/// Panics if hook could not be created
94+
pub fn create_hook_in_path(path: &Path, hook_script: &[u8]) {
95+
File::create(path).unwrap().write_all(hook_script).unwrap();
96+
97+
#[cfg(unix)]
98+
{
99+
std::process::Command::new("chmod")
100+
.arg("+x")
101+
.arg(path)
102+
// .current_dir(path)
103+
.output()
104+
.unwrap();
105+
}
106+
}

0 commit comments

Comments
 (0)