Skip to content

Commit

Permalink
Merge pull request #979 from blyxyas/shallow-clone
Browse files Browse the repository at this point in the history
Add shallow cloning capability
  • Loading branch information
ehuss committed Sep 18, 2023
2 parents ff9dca2 + 7a80cc2 commit 2b2fb37
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/remote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ pub struct RemoteHead<'remote> {
/// Options which can be specified to various fetch operations.
pub struct FetchOptions<'cb> {
callbacks: Option<RemoteCallbacks<'cb>>,
depth: i32,
proxy: Option<ProxyOptions<'cb>>,
prune: FetchPrune,
update_fetchhead: bool,
Expand Down Expand Up @@ -509,6 +510,7 @@ impl<'cb> FetchOptions<'cb> {
follow_redirects: RemoteRedirect::Initial,
custom_headers: Vec::new(),
custom_headers_ptrs: Vec::new(),
depth: 0, // Not limited depth
}
}

Expand Down Expand Up @@ -538,6 +540,17 @@ impl<'cb> FetchOptions<'cb> {
self
}

/// Set fetch depth, a value less or equal to 0 is interpreted as pull
/// everything (effectively the same as not declaring a limit depth).

// FIXME(blyxyas): We currently don't have a test for shallow functions
// because libgit2 doesn't support local shallow clones.
// https://github.com/rust-lang/git2-rs/pull/979#issuecomment-1716299900
pub fn depth(&mut self, depth: i32) -> &mut Self {
self.depth = depth.max(0);
self
}

/// Set how to behave regarding tags on the remote, such as auto-downloading
/// tags for objects we're downloading or downloading all of them.
///
Expand Down Expand Up @@ -590,7 +603,7 @@ impl<'cb> Binding for FetchOptions<'cb> {
prune: crate::call::convert(&self.prune),
update_fetchhead: crate::call::convert(&self.update_fetchhead),
download_tags: crate::call::convert(&self.download_tags),
depth: 0, // GIT_FETCH_DEPTH_FULL.
depth: self.depth,
follow_redirects: self.follow_redirects.raw(),
custom_headers: git_strarray {
count: self.custom_headers_ptrs.len(),
Expand Down

0 comments on commit 2b2fb37

Please sign in to comment.