forked from kemitix/git-next
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\")".
This commit is contained in:
parent
3dfbd44b37
commit
555aada7e9
4 changed files with 20 additions and 5 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -19,5 +19,6 @@ Cargo.lock
|
|||
|
||||
# git-next runtime files
|
||||
git-next-server.toml
|
||||
data/
|
||||
.git-next.toml
|
||||
.envrc
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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");
|
||||
}
|
||||
|
|
|
@ -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() {
|
||||
|
|
Loading…
Reference in a new issue