Skip to content

Commit 281fda0

Browse files
committed
Merge branch 'configure-prepare-fetch'
2 parents 4917beb + b5c36b8 commit 281fda0

File tree

4 files changed

+38
-4
lines changed

4 files changed

+38
-4
lines changed

gix/src/clone/access.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ impl PrepareFetch {
1010
/// _all changes done in `f()` will be persisted_.
1111
///
1212
/// It can also be used to configure additional options, like those for fetching tags. Note that
13-
/// [`with_fetch_tags()`][crate::Remote::with_fetch_tags()] should be called here to configure the clone as desired.
13+
/// [`with_fetch_tags()`](crate::Remote::with_fetch_tags()) should be called here to configure the clone as desired.
1414
/// Otherwise a clone is configured to be complete and fetches all tags, not only those reachable from all branches.
1515
pub fn configure_remote(
1616
mut self,
@@ -21,7 +21,7 @@ impl PrepareFetch {
2121
}
2222

2323
/// Set the remote's name to the given value after it was configured using the function provided via
24-
/// [`configure_remote()`][Self::configure_remote()].
24+
/// [`configure_remote()`](Self::configure_remote()).
2525
///
2626
/// If not set here, it defaults to `origin` or the value of `clone.defaultRemoteName`.
2727
pub fn with_remote_name(mut self, name: impl Into<BString>) -> Result<Self, crate::remote::name::Error> {
@@ -34,6 +34,14 @@ impl PrepareFetch {
3434
self.shallow = shallow;
3535
self
3636
}
37+
38+
/// Apply the given configuration `values` right before readying the actual fetch from the remote.
39+
/// The configuration is marked with [source API](gix_config::Source::Api), and will not be written back, it's
40+
/// retained only in memory.
41+
pub fn with_in_memory_config_overrides(mut self, values: impl IntoIterator<Item = impl Into<BString>>) -> Self {
42+
self.config_overrides = values.into_iter().map(Into::into).collect();
43+
self
44+
}
3745
}
3846

3947
/// Consumption

gix/src/clone/fetch/mod.rs

+10
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ pub enum Error {
1818
RemoteConnection(#[source] Box<dyn std::error::Error + Send + Sync>),
1919
#[error(transparent)]
2020
RemoteName(#[from] crate::config::remote::symbolic_name::Error),
21+
#[error(transparent)]
22+
ParseConfig(#[from] crate::config::overrides::Error),
23+
#[error(transparent)]
24+
ApplyConfig(#[from] crate::config::Error),
2125
#[error("Failed to load repo-local git configuration before writing")]
2226
LoadConfig(#[from] gix_config::file::init::from_paths::Error),
2327
#[error("Failed to store configured remote in memory")]
@@ -75,6 +79,12 @@ impl PrepareFetch {
7579
.as_mut()
7680
.expect("user error: multiple calls are allowed only until it succeeds");
7781

82+
if !self.config_overrides.is_empty() {
83+
let mut snapshot = repo.config_snapshot_mut();
84+
snapshot.append_config(&self.config_overrides, gix_config::Source::Api)?;
85+
snapshot.commit()?;
86+
}
87+
7888
let remote_name = match self.remote_name.as_ref() {
7989
Some(name) => name.to_owned(),
8090
None => repo

gix/src/clone/mod.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ pub struct PrepareFetch {
2020
repo: Option<crate::Repository>,
2121
/// The name of the remote, which defaults to `origin` if not overridden.
2222
remote_name: Option<BString>,
23+
/// Additional config `values` that are applied in-memory before starting the fetch process.
24+
config_overrides: Vec<BString>,
2325
/// A function to configure a remote prior to fetching a pack.
2426
configure_remote: Option<ConfigureRemoteFn>,
2527
/// A function to configure a connection before using it.
@@ -126,6 +128,7 @@ impl PrepareFetch {
126128
#[cfg(any(feature = "async-network-client", feature = "blocking-network-client"))]
127129
fetch_options: Default::default(),
128130
repo: Some(repo),
131+
config_overrides: Vec::new(),
129132
remote_name: None,
130133
configure_remote: None,
131134
#[cfg(any(feature = "async-network-client", feature = "blocking-network-client"))]
@@ -144,8 +147,6 @@ pub struct PrepareCheckout {
144147
pub(self) repo: Option<crate::Repository>,
145148
}
146149

147-
mod access;
148-
149150
// This module encapsulates functionality that works with both feature toggles. Can be combined with `fetch`
150151
// once async and clone are a thing.
151152
#[cfg(any(feature = "async-network-client", feature = "blocking-network-client"))]
@@ -181,6 +182,8 @@ mod access_feat {
181182
#[cfg(any(feature = "async-network-client-async-std", feature = "blocking-network-client"))]
182183
pub mod fetch;
183184

185+
mod access;
186+
184187
///
185188
#[cfg(feature = "worktree-mutation")]
186189
pub mod checkout;

gix/tests/clone/mod.rs

+13
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ mod blocking_io {
109109
fn from_shallow_allowed_by_default() -> crate::Result {
110110
let tmp = gix_testtools::tempfile::TempDir::new()?;
111111
let (repo, _change) = gix::prepare_clone_bare(remote::repo("base.shallow").path(), tmp.path())?
112+
.with_in_memory_config_overrides(Some("my.marker=1"))
112113
.fetch_only(gix::progress::Discard, &std::sync::atomic::AtomicBool::default())?;
113114
assert_eq!(
114115
repo.shallow_commits()?.expect("present").as_slice(),
@@ -118,6 +119,18 @@ mod blocking_io {
118119
hex_to_id("dfd0954dabef3b64f458321ef15571cc1a46d552"),
119120
]
120121
);
122+
assert_eq!(
123+
repo.config_snapshot().boolean("my.marker"),
124+
Some(true),
125+
"configuration overrides are set in time"
126+
);
127+
assert_eq!(
128+
gix::open_opts(repo.git_dir(), gix::open::Options::isolated())?
129+
.config_snapshot()
130+
.boolean("my.marker"),
131+
None,
132+
"these options are not persisted"
133+
);
121134
Ok(())
122135
}
123136

0 commit comments

Comments
 (0)