diff --git a/src/git.rs b/src/git.rs index ab24ca2..9e0c3c6 100644 --- a/src/git.rs +++ b/src/git.rs @@ -109,6 +109,12 @@ pub fn clone>(url: &str, place: P) -> Result<()> { } } +/// Rewrites an url to a SSH url. +pub fn rewrite_url(url: &str) -> Result { + let (server, owner, repo) = parse_url(url)?; + Ok(parse_to_url(&server, &owner, &repo)) +} + /// Clones a git repository in the right place. fn clone_dirty>(url: &str, place: P) -> Result<()> { let place = place.as_ref(); @@ -118,6 +124,12 @@ fn clone_dirty>(url: &str, place: P) -> Result<()> { create_dir_all(parent)?; } + let url = if env::var("GCLONE_FORCE_SSH") == Ok("true".to_owned()) { + rewrite_url(url)? + } else { + url.to_owned() + }; + let command = Command::new("git") .args(&[ "clone",