fix(#61): Format path to clone into correctly
Some checks failed
ci/woodpecker/cron/cron-docker-builder Pipeline failed
ci/woodpecker/cron/push-next Pipeline was successful
ci/woodpecker/cron/tag-created Pipeline was successful
ci/woodpecker/push/cron-docker-builder Pipeline was successful
ci/woodpecker/push/tag-created Pipeline was successful
ci/woodpecker/push/push-next Pipeline was successful

Closes kemitix/git-next#61

`GitDir` was being inserted into the command string as
"GitDir(\"data/default/foo\")".
This commit is contained in:
Paul Campbell 2024-04-23 18:53:55 +01:00
parent 3dfbd44b37
commit 555aada7e9
4 changed files with 20 additions and 5 deletions

1
.gitignore vendored
View file

@ -19,5 +19,6 @@ Cargo.lock
# git-next runtime files
git-next-server.toml
data/
.git-next.toml
.envrc

View file

@ -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 {

View file

@ -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");
}

View file

@ -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<String> = 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() {