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 tracing::info;
use tracing::{debug, info};
use crate::server::config::RepoDetails;
@ -13,17 +13,17 @@ pub enum 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> {
// INFO: gitdir validate tests that the default fetch remote matches the configured remote
let repository = gix::ThreadSafeRepository::open(repo_details.gitdir.deref())
.map_err(Box::new)?
.to_thread_local();
info!(?repository, "opened repo");
debug!(?repository, "opened repo");
let Some(remote) = repository.find_default_remote(gix::remote::Direction::Fetch) else {
return Err(Error::NoFetchRemoteFound);
};
info!(?remote, "fetch remote");
debug!(?remote, "fetch remote");
remote
.map_err(|e| Error::Fetch(e.to_string()))?

View file

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

View file

@ -15,7 +15,10 @@ pub enum Force {
}
impl std::fmt::Display for Force {
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),
}
}
}