Skip to content

Commit 3cc53dd

Browse files
committed
Pass FetchOptions for cloning
1 parent 386dcc4 commit 3cc53dd

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

src/index.rs

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,16 @@ pub struct Index {
2323
}
2424

2525
/// Options for use in `Index::from_path_or_cloned_with_options`
26-
pub struct CloneOptions {
26+
pub struct CloneOptions<'a> {
2727
pub repository_url: String,
28+
pub fetch_options: Option<git2::FetchOptions<'a>>,
2829
}
2930

30-
impl Default for CloneOptions {
31+
impl Default for CloneOptions<'static> {
3132
fn default() -> Self {
3233
CloneOptions {
3334
repository_url: INDEX_GIT_URL.into(),
35+
fetch_options: None,
3436
}
3537
}
3638
}
@@ -70,15 +72,20 @@ impl Index {
7072
/// ```
7173
pub fn from_path_or_cloned_with_options(
7274
path: impl AsRef<Path>,
73-
options: CloneOptions,
75+
CloneOptions {
76+
repository_url,
77+
fetch_options,
78+
}: CloneOptions,
7479
) -> Result<Index, GitError> {
7580
let mut repo_did_exist = true;
7681
let repo = Repository::open(path.as_ref()).or_else(|err| {
7782
if err.class() == ErrorClass::Repository {
7883
repo_did_exist = false;
79-
RepoBuilder::new()
80-
.bare(true)
81-
.clone(&options.repository_url, path.as_ref())
84+
let mut builder = RepoBuilder::new();
85+
if let Some(fo) = fetch_options {
86+
builder.fetch_options(fo);
87+
}
88+
builder.bare(true).clone(&repository_url, path.as_ref())
8289
} else {
8390
Err(err)
8491
}
@@ -89,10 +96,10 @@ impl Index {
8996
let actual_remote_url = remote
9097
.url()
9198
.ok_or_else(|| GitError::from_str("did not obtain URL of remote named 'origin'"))?;
92-
if actual_remote_url != options.repository_url {
99+
if actual_remote_url != repository_url {
93100
return Err(GitError::from_str(&format!(
94101
"Actual 'origin' remote url {:#?} did not match desired one at {:#?}",
95-
actual_remote_url, options.repository_url
102+
actual_remote_url, repository_url
96103
)));
97104
}
98105
}

0 commit comments

Comments
 (0)