From 9dcc6f6109ffcd2e60f945b273c2315d143e04a9 Mon Sep 17 00:00:00 2001 From: Kitsu Date: Fri, 30 Jul 2021 12:20:35 +0300 Subject: [PATCH] Pass FetchOptions for cloning --- src/index.rs | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/index.rs b/src/index.rs index f5d3fb5..7bd0f12 100644 --- a/src/index.rs +++ b/src/index.rs @@ -23,14 +23,16 @@ pub struct Index { } /// Options for use in `Index::from_path_or_cloned_with_options` -pub struct CloneOptions { +pub struct CloneOptions<'a> { pub repository_url: String, + pub fetch_options: Option>, } -impl Default for CloneOptions { +impl<'a> Default for CloneOptions<'a> { fn default() -> Self { CloneOptions { repository_url: INDEX_GIT_URL.into(), + fetch_options: None, } } } @@ -70,15 +72,20 @@ impl Index { /// ``` pub fn from_path_or_cloned_with_options( path: impl AsRef, - options: CloneOptions, + CloneOptions { + repository_url, + fetch_options, + }: CloneOptions, ) -> Result { let mut repo_did_exist = true; let repo = Repository::open(path.as_ref()).or_else(|err| { if err.class() == ErrorClass::Repository { repo_did_exist = false; - RepoBuilder::new() - .bare(true) - .clone(&options.repository_url, path.as_ref()) + let mut builder = RepoBuilder::new(); + if let Some(fo) = fetch_options { + builder.fetch_options(fo); + } + builder.bare(true).clone(&repository_url, path.as_ref()) } else { Err(err) } @@ -89,10 +96,10 @@ impl Index { let actual_remote_url = remote .url() .ok_or_else(|| GitError::from_str("did not obtain URL of remote named 'origin'"))?; - if actual_remote_url != options.repository_url { + if actual_remote_url != repository_url { return Err(GitError::from_str(&format!( "Actual 'origin' remote url {:#?} did not match desired one at {:#?}", - actual_remote_url, options.repository_url + actual_remote_url, repository_url ))); } }