diff --git a/src/git.rs b/src/git.rs index 3f64448..ab24ca2 100644 --- a/src/git.rs +++ b/src/git.rs @@ -74,7 +74,7 @@ fn parse_ssh_url(input: &str) -> Result<(String, String, String)> { } /// Parses a github url in the format owner/repo. -fn parse_github_url(input: &str) -> Result<(String, String, String)> { +fn parse_github_url(input: &str) -> Result<(String, String, String)> { let split = input.split("/").collect::>(); if split.len() != 2 { return Err(Error::GitUrlParseError); @@ -96,6 +96,10 @@ pub fn parse_to_url(server: &str, owner: &str, repo: &str) -> String { /// /// If an error happens, it deletes the directory created. pub fn clone>(url: &str, place: P) -> Result<()> { + if place.as_ref().exists() { + return Err(Error::PathAlreadyExists); + } + match clone_dirty(url, &place) { Ok(o) => Ok(o), Err(e) => { @@ -109,10 +113,6 @@ pub fn clone>(url: &str, place: P) -> Result<()> { fn clone_dirty>(url: &str, place: P) -> Result<()> { let place = place.as_ref(); - if place.exists() { - return Err(Error::PathAlreadyExists); - } - // Need to create the parent dir only if it exists if let Some(parent) = place.parent() { create_dir_all(parent)?; @@ -120,10 +120,10 @@ fn clone_dirty>(url: &str, place: P) -> Result<()> { let command = Command::new("git") .args(&[ - "clone", - "--recurse-submodules", - &url, - &place.display().to_string() + "clone", + "--recurse-submodules", + &url, + &place.display().to_string(), ]) .stderr(Stdio::null()) .status();