Skip to content

Commit d44f3a0

Browse files
committed
add PrepareFetch::with_leave_dirty() to avoid cleanup on drop.
1 parent cc7b614 commit d44f3a0

File tree

4 files changed

+19
-4
lines changed

4 files changed

+19
-4
lines changed

gix/src/clone/access.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,10 @@ impl PrepareFetch {
6767

6868
impl Drop for PrepareFetch {
6969
fn drop(&mut self) {
70-
if let Some(repo) = self.repo.take() {
71-
std::fs::remove_dir_all(repo.work_dir().unwrap_or_else(|| repo.path())).ok();
70+
if !self.leave_dirty {
71+
if let Some(repo) = self.repo.take() {
72+
std::fs::remove_dir_all(repo.work_dir().unwrap_or_else(|| repo.path())).ok();
73+
}
7274
}
7375
}
7476
}

gix/src/clone/checkout.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,10 @@ impl PrepareCheckout {
172172

173173
impl Drop for PrepareCheckout {
174174
fn drop(&mut self) {
175-
if let Some(repo) = self.repo.take() {
176-
std::fs::remove_dir_all(repo.work_dir().unwrap_or_else(|| repo.path())).ok();
175+
if !self.leave_dirty {
176+
if let Some(repo) = self.repo.take() {
177+
std::fs::remove_dir_all(repo.work_dir().unwrap_or_else(|| repo.path())).ok();
178+
}
177179
}
178180
}
179181
}

gix/src/clone/fetch/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ impl PrepareFetch {
227227
crate::clone::PrepareCheckout {
228228
repo: repo.into(),
229229
ref_name: self.ref_name.clone(),
230+
leave_dirty: self.leave_dirty,
230231
},
231232
fetch_outcome,
232233
))

gix/src/clone/mod.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ pub struct PrepareFetch {
3737
/// The name of the reference to fetch. If `None`, the reference pointed to by `HEAD` will be checked out.
3838
#[cfg_attr(not(feature = "blocking-network-client"), allow(dead_code))]
3939
ref_name: Option<gix_ref::PartialName>,
40+
leave_dirty: bool,
4041
}
4142

4243
/// The error returned by [`PrepareFetch::new()`].
@@ -126,6 +127,7 @@ impl PrepareFetch {
126127
configure_connection: None,
127128
shallow: remote::fetch::Shallow::NoChange,
128129
ref_name: None,
130+
leave_dirty: false,
129131
})
130132
}
131133
}
@@ -140,6 +142,7 @@ pub struct PrepareCheckout {
140142
pub(self) repo: Option<crate::Repository>,
141143
/// The name of the reference to check out. If `None`, the reference pointed to by `HEAD` will be checked out.
142144
pub(self) ref_name: Option<gix_ref::PartialName>,
145+
pub(self) leave_dirty: bool,
143146
}
144147

145148
// This module encapsulates functionality that works with both feature toggles. Can be combined with `fetch`
@@ -170,6 +173,13 @@ mod access_feat {
170173
self.fetch_options = opts;
171174
self
172175
}
176+
177+
/// Set whether to delete the repo directory when the PrepareFetch or PrepareCheckout
178+
/// object is dropped.
179+
pub fn with_leave_dirty(mut self, leave_dirty: bool) -> Self {
180+
self.leave_dirty = leave_dirty;
181+
self
182+
}
173183
}
174184
}
175185

0 commit comments

Comments
 (0)