From 555aada7e99899ed53efcf51ecd13b37dc64e0b8 Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Tue, 23 Apr 2024 18:53:55 +0100 Subject: [PATCH] fix(#61): Format path to clone into correctly Closes kemitix/git-next#61 `GitDir` was being inserted into the command string as "GitDir(\"data/default/foo\")". --- .gitignore | 1 + src/server/config/mod.rs | 2 +- src/server/config/tests.rs | 10 ++++++++++ src/server/gitforge/forgejo/repo/clone.rs | 12 ++++++++---- 4 files changed, 20 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index f5db88df..4d77f6a5 100644 --- a/.gitignore +++ b/.gitignore @@ -19,5 +19,6 @@ Cargo.lock # git-next runtime files git-next-server.toml +data/ .git-next.toml .envrc diff --git a/src/server/config/mod.rs b/src/server/config/mod.rs index d195858a..a1c2179f 100644 --- a/src/server/config/mod.rs +++ b/src/server/config/mod.rs @@ -418,7 +418,7 @@ impl GitDir { } impl std::fmt::Display for GitDir { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - write!(f, "{self:?}") + write!(f, "{}", &self.0.display()) } } impl From<&str> for GitDir { diff --git a/src/server/config/tests.rs b/src/server/config/tests.rs index 4264c683..ae12bfc9 100644 --- a/src/server/config/tests.rs +++ b/src/server/config/tests.rs @@ -132,3 +132,13 @@ fn test_repo_config_load() -> Result<(), OneOf<(toml::de::Error,)>> { Ok(()) } + +#[test] +fn gitdir_should_display_as_pathbuf() { + //given + let gitdir = GitDir::from("foo/dir"); + //when + let result = format!("{}", gitdir); + //then + assert_eq!(result, "foo/dir"); +} diff --git a/src/server/gitforge/forgejo/repo/clone.rs b/src/server/gitforge/forgejo/repo/clone.rs index f840f7d1..194eefc7 100644 --- a/src/server/gitforge/forgejo/repo/clone.rs +++ b/src/server/gitforge/forgejo/repo/clone.rs @@ -6,21 +6,25 @@ use crate::server::{ }; pub fn clone(repo_details: &RepoDetails, gitdir: GitDir) -> Result<(), RepoCloneError> { + // TODO: (#60) If directory already exists, validate it is git repo (e.g. is a git repo, + // matches the same origin) let origin = repo_details.origin(); // INFO: never log the command as it contains the API token within the 'origin' use secrecy::ExposeSecret; let command: secrecy::Secret = format!( - "/usr/bin/git clone --bare -- {} {:?}", + "/usr/bin/git clone --bare -- {} {}", origin.expose_secret(), gitdir ) .into(); let repo_name = &repo_details.repo_alias; - info!("Cloning {repo_name} to {gitdir}"); + info!( + %repo_name, + %gitdir, + "Cloning" + ); match gix::command::prepare(command.expose_secret()) .with_shell_allow_argument_splitting() - .stdout(std::process::Stdio::null()) - .stderr(std::process::Stdio::null()) .spawn() { Ok(mut child) => match child.wait() {