chore(logging): more cleaning up of logging around fetch and reset
All checks were successful
ci/woodpecker/push/push-next Pipeline was successful
ci/woodpecker/push/cron-docker-builder Pipeline was successful
ci/woodpecker/push/tag-created Pipeline was successful
ci/woodpecker/cron/cron-docker-builder Pipeline was successful
ci/woodpecker/cron/push-next Pipeline was successful
ci/woodpecker/cron/tag-created Pipeline was successful

This commit is contained in:
Paul Campbell 2024-05-04 19:57:50 +01:00
parent 7516ec1dc1
commit 709fde18d1
3 changed files with 15 additions and 10 deletions

View file

@ -1,6 +1,6 @@
use std::ops::Deref; use std::ops::Deref;
use tracing::info; use tracing::{debug, info};
use crate::server::config::RepoDetails; use crate::server::config::RepoDetails;
@ -13,17 +13,17 @@ pub enum Error {
} }
impl std::error::Error for Error {} impl std::error::Error for Error {}
#[tracing::instrument] #[tracing::instrument(skip_all, fields(repo = %repo_details))]
pub fn fetch(repo_details: &RepoDetails) -> Result<(), Error> { pub fn fetch(repo_details: &RepoDetails) -> Result<(), Error> {
// INFO: gitdir validate tests that the default fetch remote matches the configured remote // INFO: gitdir validate tests that the default fetch remote matches the configured remote
let repository = gix::ThreadSafeRepository::open(repo_details.gitdir.deref()) let repository = gix::ThreadSafeRepository::open(repo_details.gitdir.deref())
.map_err(Box::new)? .map_err(Box::new)?
.to_thread_local(); .to_thread_local();
info!(?repository, "opened repo"); debug!(?repository, "opened repo");
let Some(remote) = repository.find_default_remote(gix::remote::Direction::Fetch) else { let Some(remote) = repository.find_default_remote(gix::remote::Direction::Fetch) else {
return Err(Error::NoFetchRemoteFound); return Err(Error::NoFetchRemoteFound);
}; };
info!(?remote, "fetch remote"); debug!(?remote, "fetch remote");
remote remote
.map_err(|e| Error::Fetch(e.to_string()))? .map_err(|e| Error::Fetch(e.to_string()))?

View file

@ -10,7 +10,7 @@ use crate::server::{
}; };
// TODO: (#72) reimplement using `gix` // TODO: (#72) reimplement using `gix`
#[tracing::instrument] #[tracing::instrument(skip_all, fields(branch = %branch_name, to = %to_commit, force = %force))]
pub fn reset( pub fn reset(
repo_details: &RepoDetails, repo_details: &RepoDetails,
branch_name: BranchName, branch_name: BranchName,
@ -32,7 +32,6 @@ pub fn reset(
origin.expose_secret() origin.expose_secret()
) )
.into(); .into();
info!("Resetting {branch_name} to {to_commit}");
let ctx = gix::diff::command::Context { let ctx = gix::diff::command::Context {
git_dir: Some(gitdir.to_path_buf()), git_dir: Some(gitdir.to_path_buf()),
..Default::default() ..Default::default()
@ -41,12 +40,15 @@ pub fn reset(
match gix::command::prepare(command.expose_secret()) match gix::command::prepare(command.expose_secret())
.with_context(ctx) .with_context(ctx)
.with_shell_allow_argument_splitting() .with_shell_allow_argument_splitting()
// .stdout(std::process::Stdio::null()) .stdout(std::process::Stdio::null())
// .stderr(std::process::Stdio::null()) .stderr(std::process::Stdio::null())
.spawn() .spawn()
{ {
Ok(mut child) => match child.wait() { Ok(mut child) => match child.wait() {
Ok(_) => Ok(()), Ok(_) => {
info!("Branch updated");
Ok(())
}
Err(err) => { Err(err) => {
warn!(?err, "Failed (wait)"); warn!(?err, "Failed (wait)");
Err(BranchResetError::Push) Err(BranchResetError::Push)

View file

@ -15,7 +15,10 @@ pub enum Force {
} }
impl std::fmt::Display for Force { impl std::fmt::Display for Force {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{:?}", self) match self {
Self::No => write!(f, "fast-foward"),
Self::From(from) => write!(f, "force-if-from:{}", from),
}
} }
} }