Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add PrepareFetch::with_leave_dirty() to avoid cleanup on drop. #1805

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions gix/src/clone/access.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,10 @@ impl PrepareFetch {

impl Drop for PrepareFetch {
fn drop(&mut self) {
if let Some(repo) = self.repo.take() {
std::fs::remove_dir_all(repo.work_dir().unwrap_or_else(|| repo.path())).ok();
if !self.leave_dirty {
if let Some(repo) = self.repo.take() {
std::fs::remove_dir_all(repo.work_dir().unwrap_or_else(|| repo.path())).ok();
}
}
}
}
Expand Down
6 changes: 4 additions & 2 deletions gix/src/clone/checkout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,10 @@ impl PrepareCheckout {

impl Drop for PrepareCheckout {
fn drop(&mut self) {
if let Some(repo) = self.repo.take() {
std::fs::remove_dir_all(repo.work_dir().unwrap_or_else(|| repo.path())).ok();
if !self.leave_dirty {
if let Some(repo) = self.repo.take() {
std::fs::remove_dir_all(repo.work_dir().unwrap_or_else(|| repo.path())).ok();
}
}
}
}
Expand Down
1 change: 1 addition & 0 deletions gix/src/clone/fetch/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ impl PrepareFetch {
crate::clone::PrepareCheckout {
repo: repo.into(),
ref_name: self.ref_name.clone(),
leave_dirty: self.leave_dirty,
},
fetch_outcome,
))
Expand Down
10 changes: 10 additions & 0 deletions gix/src/clone/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ pub struct PrepareFetch {
/// The name of the reference to fetch. If `None`, the reference pointed to by `HEAD` will be checked out.
#[cfg_attr(not(feature = "blocking-network-client"), allow(dead_code))]
ref_name: Option<gix_ref::PartialName>,
leave_dirty: bool,
}

/// The error returned by [`PrepareFetch::new()`].
Expand Down Expand Up @@ -126,6 +127,7 @@ impl PrepareFetch {
configure_connection: None,
shallow: remote::fetch::Shallow::NoChange,
ref_name: None,
leave_dirty: false,
})
}
}
Expand All @@ -140,6 +142,7 @@ pub struct PrepareCheckout {
pub(self) repo: Option<crate::Repository>,
/// The name of the reference to check out. If `None`, the reference pointed to by `HEAD` will be checked out.
pub(self) ref_name: Option<gix_ref::PartialName>,
pub(self) leave_dirty: bool,
}

// This module encapsulates functionality that works with both feature toggles. Can be combined with `fetch`
Expand Down Expand Up @@ -170,6 +173,13 @@ mod access_feat {
self.fetch_options = opts;
self
}

/// Set whether to delete the repo directory when the PrepareFetch or PrepareCheckout
/// object is dropped.
pub fn with_leave_dirty(mut self, leave_dirty: bool) -> Self {
self.leave_dirty = leave_dirty;
self
}
}
}

Expand Down
Loading