diff options
Diffstat (limited to 'server/src/git.rs')
| -rw-r--r-- | server/src/git.rs | 34 |
1 files changed, 16 insertions, 18 deletions
diff --git a/server/src/git.rs b/server/src/git.rs index 58d2fda..a05c670 100644 --- a/server/src/git.rs +++ b/server/src/git.rs @@ -46,6 +46,7 @@ pub struct Repository { remote: Option<String>, project_id: Option<String>, socket: Option<PathBuf>, + githook: Option<PathBuf>, // Lock for any repo task, 90% of all tasks are readers but there are some writers // where nothing else may be done. @@ -147,7 +148,14 @@ impl RepoData { } async fn sync_hooks(&mut self, repo: &Repository) -> Result<(), Error> { - let hook = get_githook_bin()?; + let hook = match repo.githook() { + Some(path) => PathBuf::from(path), + None => { + let server_exe = + std::env::current_exe().map_err(|e| io_err("unable to get current exe", e))?; + server_exe.parent().unwrap().join("eyeballs-githook") + } + }; let hooks = if repo.is_bare() { repo.path().join("hooks") @@ -409,9 +417,11 @@ impl Repository { bare: bool, remote: Option<impl Into<String>>, project_id: Option<impl Into<String>>, + githook: Option<impl Into<PathBuf>>, ) -> Self { let path = path.into(); let project_id = project_id.map(|x| x.into()); + let githook = githook.map(|x| x.into()); let socket: Option<PathBuf>; if let Some(project_id) = &project_id { socket = Some( @@ -428,6 +438,7 @@ impl Repository { project_id, path, socket, + githook, bare, lock: RwLock::new(RepoData::new()), } @@ -449,6 +460,10 @@ impl Repository { self.socket.as_deref() } + fn githook(&self) -> Option<&Path> { + self.githook.as_deref() + } + pub fn is_bare(&self) -> bool { self.bare } @@ -520,20 +535,3 @@ impl Repository { data.get_commiter(self, commit.as_str()).await } } - -#[cfg(not(test))] -fn get_githook_bin() -> Result<PathBuf, Error> { - let server_exe = std::env::current_exe().map_err(|e| io_err("unable to get current exe", e))?; - Ok(server_exe.parent().unwrap().join("eyeballs-githook")) -} - -#[cfg(test)] -fn get_githook_bin() -> Result<PathBuf, Error> { - let test_exe = std::env::current_exe().map_err(|e| io_err("unable to get current exe", e))?; - Ok(test_exe - .parent() - .unwrap() - .parent() - .unwrap() - .join("eyeballs-githook")) -} |
