summaryrefslogtreecommitdiff
path: root/server/src
diff options
context:
space:
mode:
Diffstat (limited to 'server/src')
-rw-r--r--server/src/git.rs34
-rw-r--r--server/src/git_root.rs3
-rw-r--r--server/src/githook.rs8
-rw-r--r--server/src/tests.rs9
4 files changed, 35 insertions, 19 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"))
-}
diff --git a/server/src/git_root.rs b/server/src/git_root.rs
index 4da8f43..31e4d45 100644
--- a/server/src/git_root.rs
+++ b/server/src/git_root.rs
@@ -25,6 +25,7 @@ type DbConnection = <DbPool as Pool>::Connection;
#[derive(Debug, Deserialize)]
pub struct Config<'a> {
git_server_root: Cow<'a, str>,
+ git_hook: Cow<'a, str>,
}
struct RootsData {
@@ -396,11 +397,13 @@ async fn setup_project_root(
) -> Result<Arc<git::Repository>, git::Error> {
let mut path = PathBuf::from(config.git_server_root.to_string());
path.push(project_id);
+ let githook = PathBuf::from(config.git_hook.to_string());
let repo = Arc::new(git::Repository::new(
path,
true,
Some(remote),
Some(project_id),
+ Some(githook),
));
repo.setup().await?;
diff --git a/server/src/githook.rs b/server/src/githook.rs
index 24b4359..2e1de13 100644
--- a/server/src/githook.rs
+++ b/server/src/githook.rs
@@ -52,7 +52,13 @@ async fn main() -> Result<(), Box<dyn Error>> {
receive: Vec::new(),
};
- let repo = git::Repository::new(PathBuf::from("."), true, None::<String>, None::<String>);
+ let repo = git::Repository::new(
+ PathBuf::from("."),
+ true,
+ None::<String>,
+ None::<String>,
+ None::<PathBuf>,
+ );
while let Some(line) = lines.next_line().await? {
let data: Vec<&str> = line.split(' ').collect();
diff --git a/server/src/tests.rs b/server/src/tests.rs
index d59dcbe..1b42485 100644
--- a/server/src/tests.rs
+++ b/server/src/tests.rs
@@ -116,11 +116,20 @@ async fn async_client_with_private_database(test_name: String) -> Client {
};
let git_root = testdir!();
+ let git_hook = std::env::current_exe()
+ .unwrap()
+ .parent()
+ .unwrap()
+ .parent()
+ .unwrap()
+ .join("eyeballs-githook");
+
let authorized_keys = git_root.join("authorized_keys");
let figment = base_figment
.merge(("databases", map!["eyeballs" => db_config]))
.merge(("git_server_root", git_root))
+ .merge(("git_hook", git_hook))
.merge(("authorized_keys", authorized_keys));
Client::tracked(crate::rocket_from_config(figment))