git_clone_canonical/
clone.rs1use crate::{get_repo_path, git, log_init, BaseDir, Error, Result, Url};
2use std::path::PathBuf;
3
4pub fn clone(basedir: BaseDir, url: Url) -> Result<()> {
5 log_init()?;
6 let repopath = get_repo_path(basedir, &url);
7 log::info!("repository path {:?}", repopath.display());
8 if repopath.exists() {
9 git::fetch(&repopath, url)
10 } else {
11 new_clone(repopath, url)
12 }
13}
14
15fn new_clone(repopath: PathBuf, url: Url) -> Result<()> {
16 let parent = repopath
17 .parent()
18 .ok_or_else(|| Error::InvalidRepoPath(repopath.clone()))?;
19 if !parent.exists() {
20 log::info!("creating parent directory {:?}", parent.display());
21 std::fs::create_dir_all(parent)?;
22 }
23 git::clone(parent, url)
24}