fn clone_or_fetch_repo(git_dir: &std::path::Path, repo_config: &RepoConfig) -> Result<(), Error> {
    let git_ssh_command = match &repo_config.deploy_key_path {
        Some(path) => format!("ssh -i {} -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no", path.display()),
        None => "ssh".to_string(),
    };

    if git_dir.is_dir() {
        info!("fetching for {:?}", git_dir);
        let fetch = std::process::Command::new("git")
            .env("GIT_SSH_COMMAND", git_ssh_command)
            .arg("--git-dir")
            .arg(git_dir)
            .arg("fetch")
            .status()
            .expect("git fetch failed");
        if fetch.success() {
            Ok(())
        } else {
            Err(Error::FetchFailed)
        }
    } else {
        // TODO make repo configurable + ssh key env
        info!("cloning {:?} to {:?}", repo_config.url, git_dir);
        let clone = std::process::Command::new("git")
            .env("GIT_SSH_COMMAND", git_ssh_command)
            .arg("clone")
            .arg("--bare")
            .arg(&repo_config.url)
            .arg(git_dir)
            .status()
            .expect("git clone failed");
        if clone.success() {
            Ok(())
        } else {
            error!("repo_config {:?}", repo_config);
            Err(Error::CloneFailed)
        }
    }
}
/// clones (or fetches if already cloned) a git repo.
clones (or fetches if already cloned) a git repo.
clones ( or fetches if already cloned ) a git repo .
fn clone_or_fetch_repo(git_dir: &std::path::Path, repo_config: &RepoConfig) -> Result<(), Error> {
    let git_ssh_command = match &repo_config.deploy_key_path {
        Some(path) => format!("ssh -i {} -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no", path.display()),
        None => "ssh".to_string(),
    };
    if git_dir.is_dir() {
        info!("fetching for {:?}", git_dir);
        let fetch = std::process::Command::new("git")
            .env("GIT_SSH_COMMAND", git_ssh_command)
            .arg("--git-dir")
            .arg(git_dir)
            .arg("fetch")
            .status()
            .expect("git fetch failed");
        if fetch.success() {
            Ok(())
        } else {
            Err(Error::FetchFailed)
        }
    } else {
        // TODO make repo configurable + ssh key env
        info!("cloning {:?} to {:?}", repo_config.url, git_dir);
        let clone = std::process::Command::new("git")
            .env("GIT_SSH_COMMAND", git_ssh_command)
            .arg("clone")
            .arg("--bare")
            .arg(&repo_config.url)
            .arg(git_dir)
            .status()
            .expect("git clone failed");
        if clone.success() {
            Ok(())
        } else {
            error!("repo_config {:?}", repo_config);
            Err(Error::CloneFailed)
        }
    }
}
fn clone_or_fetch_repo ( git_dir : & std :: path :: Path , repo_config : & RepoConfig ) -> Result < ( ) , Error > { let git_ssh_command = match & repo_config . deploy_key_path { Some ( path ) => format ! ( " " path display ( ) ) , None => " " . to_string ( ) , } ; if git_dir . is_dir ( ) { info ! ( " " git_dir ) ; let fetch = std :: process :: Command :: new ( " " ) . env ( " " , git_ssh_command ) . arg ( " " ) . arg ( git_dir ) . arg ( " " ) . status ( ) . expect ( " " ) ; if fetch . success ( ) { Ok ( ( ) ) } else { Err ( Error :: FetchFailed ) } } else { // TODO make repo configurable + ssh key env info ! ( " " repo_config url git_dir ) ; let clone = std :: process :: Command :: new ( " " ) . env ( " " , git_ssh_command ) . arg ( " " ) . arg ( " " ) . arg ( & repo_config . url ) . arg ( git_dir ) . status ( ) . expect ( " " ) ; if clone . success ( ) { Ok ( ( ) ) } else { error ! ( " " repo_config ) ; Err ( Error :: CloneFailed ) } } }
clones (or fetches if already cloned) a git repo.
clones ( or fetches if already cloned ) a git repo .
git_dir
&std::path::Path
repo_config
&RepoConfig
git_dir
&std::path::Path
repo_config
&RepoConfig