Skip to content

Commit

Permalink
Allow overriding Git configuration when cloning.
Browse files Browse the repository at this point in the history
  • Loading branch information
bittrance committed Dec 8, 2023
1 parent 4917beb commit 9833b45
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
7 changes: 7 additions & 0 deletions gix/src/clone/access.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ impl PrepareFetch {
self.shallow = shallow;
self
}

/// Apply the given configuration `values` early to allow affecting the repository instantiation phase.
/// The configuration is marked with [source API][gix_config::Source::Api].
pub fn config_overrides(mut self, values: impl IntoIterator<Item = impl Into<BString>>) -> Self {
self.api_config_overrides = values.into_iter().map(Into::into).collect();
self
}
}

/// Consumption
Expand Down
8 changes: 8 additions & 0 deletions gix/src/clone/fetch/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ pub enum Error {
RemoteConnection(#[source] Box<dyn std::error::Error + Send + Sync>),
#[error(transparent)]
RemoteName(#[from] crate::config::remote::symbolic_name::Error),
#[error(transparent)]
ParseConfig(#[from] crate::config::overrides::Error),
#[error(transparent)]
ApplyConfig(#[from] crate::config::Error),
#[error("Failed to load repo-local git configuration before writing")]
LoadConfig(#[from] gix_config::file::init::from_paths::Error),
#[error("Failed to store configured remote in memory")]
Expand Down Expand Up @@ -75,6 +79,10 @@ impl PrepareFetch {
.as_mut()
.expect("user error: multiple calls are allowed only until it succeeds");

let mut snapshot = repo.config_snapshot_mut();
snapshot.append_config(self.api_config_overrides.as_slice(), gix_config::Source::Api)?;
snapshot.commit()?;

let remote_name = match self.remote_name.as_ref() {
Some(name) => name.to_owned(),
None => repo
Expand Down
3 changes: 3 additions & 0 deletions gix/src/clone/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ pub struct PrepareFetch {
repo: Option<crate::Repository>,
/// The name of the remote, which defaults to `origin` if not overridden.
remote_name: Option<BString>,
/// Additional config `values` that are applied in-memory before starting the fetch process.
api_config_overrides: Vec<BString>,
/// A function to configure a remote prior to fetching a pack.
configure_remote: Option<ConfigureRemoteFn>,
/// A function to configure a connection before using it.
Expand Down Expand Up @@ -126,6 +128,7 @@ impl PrepareFetch {
#[cfg(any(feature = "async-network-client", feature = "blocking-network-client"))]
fetch_options: Default::default(),
repo: Some(repo),
api_config_overrides: Vec::new(),
remote_name: None,
configure_remote: None,
#[cfg(any(feature = "async-network-client", feature = "blocking-network-client"))]
Expand Down

0 comments on commit 9833b45

Please sign in to comment.