Skip to content

Commit eaef987

Browse files
committed
Add example for fetch options. (#11)
1 parent 091ef7d commit eaef987

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

src/index.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,34 @@ impl Index {
7070
/// let index = Index::from_path_or_cloned_with_options(path, options)?;
7171
/// # Ok::<(), git2::Error>(())
7272
/// ```
73+
/// Or to access a private repository, use fetch options.
74+
///
75+
/// ```no_run
76+
/// use crates_index_diff::{CloneOptions, Index};
77+
/// let fo = {
78+
/// let mut fo = git2::FetchOptions::new();
79+
/// fo.remote_callbacks({
80+
/// let mut callbacks = git2::RemoteCallbacks::new();
81+
/// callbacks.credentials(|_url, username_from_url, _allowed_types| {
82+
/// git2::Cred::ssh_key_from_memory(
83+
/// username_from_url.unwrap(),
84+
/// None,
85+
/// &std::env::var("PRIVATE_KEY").unwrap(),
86+
/// None,
87+
/// )
88+
/// });
89+
/// callbacks
90+
/// });
91+
/// fo
92+
/// };
93+
/// Index::from_path_or_cloned_with_options(
94+
/// "index",
95+
/// CloneOptions {
96+
/// repository_url: "[email protected]:private-index/goes-here.git".into(),
97+
/// fetch_options: Some(fo),
98+
/// },
99+
/// ).unwrap();
100+
/// ```
73101
pub fn from_path_or_cloned_with_options(
74102
path: impl AsRef<Path>,
75103
CloneOptions {

0 commit comments

Comments
 (0)