Adds support for GCLONE_FORCE_SSH env

This commit is contained in:
Thomas Forgione 2020-11-04 12:53:59 +01:00
parent 9fefbb8c3a
commit d5f8834bcb
1 changed files with 12 additions and 0 deletions

View File

@ -109,6 +109,12 @@ pub fn clone<P: AsRef<Path>>(url: &str, place: P) -> Result<()> {
}
}
/// Rewrites an url to a SSH url.
pub fn rewrite_url(url: &str) -> Result<String> {
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<P: AsRef<Path>>(url: &str, place: P) -> Result<()> {
let place = place.as_ref();
@ -118,6 +124,12 @@ fn clone_dirty<P: AsRef<Path>>(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",