Skip to content

Commit

Permalink
Merge pull request #122 from SierraSoftworks/feat/committer
Browse files Browse the repository at this point in the history
fix: Configure a fallback git committer for clones and fetches
  • Loading branch information
notheotherben authored Dec 10, 2024
2 parents 6dfa73e + 461b833 commit a862635
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/engines/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ impl GitEngine {
"Make sure that your internet connectivity is working correctly, and that your local git configuration is able to clone this repo.",
e))?;

trace!("Configure fallback committer information");
self.ensure_committer(&repository)?;

trace!("Configuring core.bare for Git repository");
self.update_config(&repository, |c| {
c.set_raw_value(&gix::config::tree::Core::BARE, "true").map_err(|e| errors::system_with_internal(
Expand Down Expand Up @@ -132,6 +135,8 @@ impl GitEngine {
)
})?;

self.ensure_committer(&repository)?;

let original_head = repository.head_id().ok();

let default_refspecs = vec!["+refs/heads/*:refs/remotes/origin/*".to_string()];
Expand Down Expand Up @@ -260,6 +265,27 @@ impl GitEngine {
}
}

fn ensure_committer(&self, repo: &gix::Repository) -> Result<(), errors::Error> {
if repo.committer().is_none() {
self.update_config(repo, |cfg| {
cfg.set_raw_value(
&gix::config::tree::gitoxide::Committer::NAME_FALLBACK,
"github-backup",
)
.expect("works - statically known");
cfg.set_raw_value(
&gix::config::tree::gitoxide::Committer::EMAIL_FALLBACK,
"[email protected]",
)
.expect("works - statically known");

Ok(())
})
} else {
Ok(())
}
}

fn update_config<U>(&self, repo: &gix::Repository, mut update: U) -> Result<(), errors::Error>
where
U: FnMut(&mut gix::config::File<'_>) -> Result<(), errors::Error>,
Expand Down

0 comments on commit a862635

Please sign in to comment.