From d5f8834bcb6f6e7d9e032ea4b56849627e1c4f4c Mon Sep 17 00:00:00 2001 From: Thomas Forgione Date: Wed, 4 Nov 2020 12:53:59 +0100 Subject: [PATCH] Adds support for GCLONE_FORCE_SSH env --- src/git.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) 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",