Skip to content

Commit 5cf6d05

Browse files
authored
Merge pull request #2048 from ralphmodales/fetch-without-commiter-config
add committer fallback for fetch
2 parents 391dd04 + d7db360 commit 5cf6d05

File tree

6 files changed

+29
-17
lines changed

6 files changed

+29
-17
lines changed

gix/src/clone/fetch/mod.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ pub enum Error {
4545
wanted: gix_ref::PartialName,
4646
candidates: Vec<BString>,
4747
},
48+
#[error(transparent)]
49+
CommitterOrFallback(#[from] crate::config::time::Error),
4850
}
4951

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

85+
repo.committer_or_set_generic_fallback()?;
86+
8387
if !self.config_overrides.is_empty() {
8488
let mut snapshot = repo.config_snapshot_mut();
8589
snapshot.append_config(&self.config_overrides, gix_config::Source::Api)?;
86-
snapshot.commit()?;
8790
}
8891

8992
let remote_name = match self.remote_name.as_ref() {

gix/src/clone/mod.rs

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#![allow(clippy::result_large_err)]
2-
use crate::{bstr::BString, config::tree::gitoxide, remote};
2+
use crate::{bstr::BString, remote};
33

44
type ConfigureRemoteFn =
55
Box<dyn FnMut(crate::Remote<'_>) -> Result<crate::Remote<'_>, Box<dyn std::error::Error + Send + Sync>>>;
@@ -46,6 +46,8 @@ pub enum Error {
4646
#[error(transparent)]
4747
Init(#[from] crate::init::Error),
4848
#[error(transparent)]
49+
CommitterOrFallback(#[from] crate::config::time::Error),
50+
#[error(transparent)]
4951
UrlParse(#[from] gix_url::parse::Error),
5052
#[error("Failed to turn a the relative file url \"{}\" into an absolute one", url.to_bstring())]
5153
CanonicalizeUrl {
@@ -102,18 +104,7 @@ impl PrepareFetch {
102104
url: url.clone(),
103105
source: err,
104106
})?;
105-
if repo.committer().is_none() {
106-
let mut config = gix_config::File::new(gix_config::file::Metadata::api());
107-
config
108-
.set_raw_value(&gitoxide::Committer::NAME_FALLBACK, "no name configured during clone")
109-
.expect("works - statically known");
110-
config
111-
.set_raw_value(&gitoxide::Committer::EMAIL_FALLBACK, "[email protected]")
112-
.expect("works - statically known");
113-
let mut repo_config = repo.config_snapshot_mut();
114-
repo_config.append(config);
115-
repo_config.commit().expect("configuration is still valid");
116-
}
107+
repo.committer_or_set_generic_fallback()?;
117108
Ok(PrepareFetch {
118109
url,
119110
#[cfg(any(feature = "async-network-client", feature = "blocking-network-client"))]

gix/src/repository/identity.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,24 @@ impl crate::Repository {
4343
.into()
4444
}
4545

46+
/// Return the committer or its fallback just like [`committer()`](Self::committer()), but if *not* set generate a
47+
/// possibly arbitrary fallback and configure it in memory on this instance. That fallback is then returned and future
48+
/// calls to [`committer()`](Self::committer()) will return it as well.
49+
pub fn committer_or_set_generic_fallback(&mut self) -> Result<gix_actor::SignatureRef<'_>, config::time::Error> {
50+
if self.committer().is_none() {
51+
let mut config = gix_config::File::new(gix_config::file::Metadata::api());
52+
config
53+
.set_raw_value(&gitoxide::Committer::NAME_FALLBACK, "no name configured")
54+
.expect("works - statically known");
55+
config
56+
.set_raw_value(&gitoxide::Committer::EMAIL_FALLBACK, "[email protected]")
57+
.expect("works - statically known");
58+
let mut repo_config = self.config_snapshot_mut();
59+
repo_config.append(config);
60+
}
61+
self.committer().expect("committer was just set")
62+
}
63+
4664
/// Return the author as configured by this repository, which is determined by…
4765
///
4866
/// * …the git configuration `author.name|email`…

gix/tests/gix-init.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ mod with_overrides {
268268
Ok(())
269269
}
270270

271-
fn cow_bstr(s: &str) -> Cow<BStr> {
271+
fn cow_bstr(s: &str) -> Cow<'_, BStr> {
272272
Cow::Borrowed(s.into())
273273
}
274274
}

gix/tests/gix/clone.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ mod blocking_io {
334334
.expect("one line")?
335335
.signature
336336
.to_owned()?;
337-
assert_eq!(sig.name, "no name configured during clone");
337+
assert_eq!(sig.name, "no name configured");
338338
assert_eq!(sig.email, "[email protected]");
339339

340340
match out.status {

gix/tests/gix/object/tree/diff.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -879,7 +879,7 @@ mod track_rewrites {
879879
}
880880
}
881881

882-
fn tree_named(repo: &gix::Repository, rev_spec: impl AsRef<str>) -> gix::Tree {
882+
fn tree_named(repo: &gix::Repository, rev_spec: impl AsRef<str>) -> gix::Tree<'_> {
883883
repo.rev_parse_single(rev_spec.as_ref())
884884
.unwrap()
885885
.object()

0 commit comments

Comments
 (0)