@@ -23,14 +23,16 @@ pub struct Index {
23
23
}
24
24
25
25
/// Options for use in `Index::from_path_or_cloned_with_options`
26
- pub struct CloneOptions {
26
+ pub struct CloneOptions < ' a > {
27
27
pub repository_url : String ,
28
+ pub fetch_options : Option < git2:: FetchOptions < ' a > > ,
28
29
}
29
30
30
- impl Default for CloneOptions {
31
+ impl Default for CloneOptions < ' static > {
31
32
fn default ( ) -> Self {
32
33
CloneOptions {
33
34
repository_url : INDEX_GIT_URL . into ( ) ,
35
+ fetch_options : None ,
34
36
}
35
37
}
36
38
}
@@ -70,15 +72,20 @@ impl Index {
70
72
/// ```
71
73
pub fn from_path_or_cloned_with_options (
72
74
path : impl AsRef < Path > ,
73
- options : CloneOptions ,
75
+ CloneOptions {
76
+ repository_url,
77
+ fetch_options,
78
+ } : CloneOptions ,
74
79
) -> Result < Index , GitError > {
75
80
let mut repo_did_exist = true ;
76
81
let repo = Repository :: open ( path. as_ref ( ) ) . or_else ( |err| {
77
82
if err. class ( ) == ErrorClass :: Repository {
78
83
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 ( ) )
82
89
} else {
83
90
Err ( err)
84
91
}
@@ -89,10 +96,10 @@ impl Index {
89
96
let actual_remote_url = remote
90
97
. url ( )
91
98
. 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 {
93
100
return Err ( GitError :: from_str ( & format ! (
94
101
"Actual 'origin' remote url {:#?} did not match desired one at {:#?}" ,
95
- actual_remote_url, options . repository_url
102
+ actual_remote_url, repository_url
96
103
) ) ) ;
97
104
}
98
105
}
0 commit comments