Skip to content

add committer fallback for fetch #2048

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

Merged
merged 2 commits into from
Jun 23, 2025
Merged
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
5 changes: 4 additions & 1 deletion gix/src/clone/fetch/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ pub enum Error {
wanted: gix_ref::PartialName,
candidates: Vec<BString>,
},
#[error(transparent)]
CommitterOrFallback(#[from] crate::config::time::Error),
}

/// Modification
Expand Down Expand Up @@ -80,10 +82,11 @@ impl PrepareFetch {
.as_mut()
.expect("user error: multiple calls are allowed only until it succeeds");

repo.committer_or_set_generic_fallback()?;

if !self.config_overrides.is_empty() {
let mut snapshot = repo.config_snapshot_mut();
snapshot.append_config(&self.config_overrides, gix_config::Source::Api)?;
snapshot.commit()?;
}

let remote_name = match self.remote_name.as_ref() {
Expand Down
17 changes: 4 additions & 13 deletions gix/src/clone/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#![allow(clippy::result_large_err)]
use crate::{bstr::BString, config::tree::gitoxide, remote};
use crate::{bstr::BString, remote};

type ConfigureRemoteFn =
Box<dyn FnMut(crate::Remote<'_>) -> Result<crate::Remote<'_>, Box<dyn std::error::Error + Send + Sync>>>;
Expand Down Expand Up @@ -46,6 +46,8 @@ pub enum Error {
#[error(transparent)]
Init(#[from] crate::init::Error),
#[error(transparent)]
CommitterOrFallback(#[from] crate::config::time::Error),
#[error(transparent)]
UrlParse(#[from] gix_url::parse::Error),
#[error("Failed to turn a the relative file url \"{}\" into an absolute one", url.to_bstring())]
CanonicalizeUrl {
Expand Down Expand Up @@ -102,18 +104,7 @@ impl PrepareFetch {
url: url.clone(),
source: err,
})?;
if repo.committer().is_none() {
let mut config = gix_config::File::new(gix_config::file::Metadata::api());
config
.set_raw_value(&gitoxide::Committer::NAME_FALLBACK, "no name configured during clone")
.expect("works - statically known");
config
.set_raw_value(&gitoxide::Committer::EMAIL_FALLBACK, "[email protected]")
.expect("works - statically known");
let mut repo_config = repo.config_snapshot_mut();
repo_config.append(config);
repo_config.commit().expect("configuration is still valid");
}
repo.committer_or_set_generic_fallback()?;
Ok(PrepareFetch {
url,
#[cfg(any(feature = "async-network-client", feature = "blocking-network-client"))]
Expand Down
18 changes: 18 additions & 0 deletions gix/src/repository/identity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,24 @@ impl crate::Repository {
.into()
}

/// Return the committer or its fallback just like [`committer()`](Self::committer()), but if *not* set generate a
/// possibly arbitrary fallback and configure it in memory on this instance. That fallback is then returned and future
/// calls to [`committer()`](Self::committer()) will return it as well.
pub fn committer_or_set_generic_fallback(&mut self) -> Result<gix_actor::SignatureRef<'_>, config::time::Error> {
if self.committer().is_none() {
let mut config = gix_config::File::new(gix_config::file::Metadata::api());
config
.set_raw_value(&gitoxide::Committer::NAME_FALLBACK, "no name configured")
.expect("works - statically known");
config
.set_raw_value(&gitoxide::Committer::EMAIL_FALLBACK, "[email protected]")
.expect("works - statically known");
let mut repo_config = self.config_snapshot_mut();
repo_config.append(config);
}
self.committer().expect("committer was just set")
}

/// Return the author as configured by this repository, which is determined by…
///
/// * …the git configuration `author.name|email`…
Expand Down
2 changes: 1 addition & 1 deletion gix/tests/gix-init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ mod with_overrides {
Ok(())
}

fn cow_bstr(s: &str) -> Cow<BStr> {
fn cow_bstr(s: &str) -> Cow<'_, BStr> {
Cow::Borrowed(s.into())
}
}
Expand Down
2 changes: 1 addition & 1 deletion gix/tests/gix/clone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ mod blocking_io {
.expect("one line")?
.signature
.to_owned()?;
assert_eq!(sig.name, "no name configured during clone");
assert_eq!(sig.name, "no name configured");
assert_eq!(sig.email, "[email protected]");

match out.status {
Expand Down
2 changes: 1 addition & 1 deletion gix/tests/gix/object/tree/diff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -879,7 +879,7 @@ mod track_rewrites {
}
}

fn tree_named(repo: &gix::Repository, rev_spec: impl AsRef<str>) -> gix::Tree {
fn tree_named(repo: &gix::Repository, rev_spec: impl AsRef<str>) -> gix::Tree<'_> {
repo.rev_parse_single(rev_spec.as_ref())
.unwrap()
.object()
Expand Down
Loading