Skip to content

Commit 39180b4

Browse files
committed
improve documentation of PrepareCheckout and make it easier to use
Now it's clear why it does what it does with the internal repository, even though admittedly it could also be made so that it can be called multiple times (despite making no sense).
1 parent 9bf01e4 commit 39180b4

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

gix/src/clone/checkout.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,12 @@ pub mod main_worktree {
6565
///
6666
/// Note that this is a no-op if the remote was empty, leaving this repository empty as well. This can be validated by checking
6767
/// if the `head()` of the returned repository is *not* unborn.
68+
///
69+
/// # Panics
70+
///
71+
/// If called after it was successful. The reason here is that it auto-deletes the contained repository,
72+
/// and keeps track of this by means of keeping just one repository instance, which is passed to the user
73+
/// after success.
6874
pub fn main_worktree<P>(
6975
&mut self,
7076
mut progress: P,
@@ -86,7 +92,7 @@ pub mod main_worktree {
8692
let repo = self
8793
.repo
8894
.as_ref()
89-
.expect("still present as we never succeeded the worktree checkout yet");
95+
.expect("BUG: this method may only be called until it is successful");
9096
let workdir = repo.work_dir().ok_or_else(|| Error::BareRepository {
9197
git_dir: repo.git_dir().to_owned(),
9298
})?;
@@ -138,7 +144,7 @@ pub mod main_worktree {
138144
bytes.show_throughput(start);
139145

140146
index.write(Default::default())?;
141-
Ok((self.repo.take().expect("still present"), outcome))
147+
Ok((self.repo.take().expect("still present").clone(), outcome))
142148
}
143149
}
144150
}

gix/src/clone/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,13 +140,13 @@ impl PrepareFetch {
140140
}
141141
}
142142

143-
/// A utility to collect configuration on how to perform a checkout into a working tree, and when dropped without checking out successfully
144-
/// the fetched repository will be dropped.
143+
/// A utility to collect configuration on how to perform a checkout into a working tree,
144+
/// and when dropped without checking out successfully the fetched repository will be deleted from disk.
145145
#[must_use]
146146
#[cfg(feature = "worktree-mutation")]
147147
#[derive(Debug)]
148148
pub struct PrepareCheckout {
149-
/// A freshly initialized repository which is owned by us, or `None` if it was handed to the user
149+
/// A freshly initialized repository which is owned by us, or `None` if it was successfully checked out.
150150
pub(self) repo: Option<crate::Repository>,
151151
/// The name of the reference to check out. If `None`, the reference pointed to by `HEAD` will be checked out.
152152
pub(self) ref_name: Option<gix_ref::PartialName>,

0 commit comments

Comments
 (0)