From 96e5881665dce806b489a350a2d85bf1642ef0ad Mon Sep 17 00:00:00 2001 From: Joscha Date: Thu, 17 Aug 2023 15:42:16 +0200 Subject: [PATCH] Log fetched refs --- src/git.rs | 5 ++--- src/server.rs | 4 +++- src/server/recurring/fetch.rs | 11 ++++++++--- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/git.rs b/src/git.rs index ea38f64..0c65574 100644 --- a/src/git.rs +++ b/src/git.rs @@ -102,7 +102,7 @@ pub fn fetch_head(path: &Path, url: &str) -> Result<(), Error> { Ok(()) } -pub fn fetch(path: &Path, url: &str, refspecs: &[String]) -> Result<(), Error> { +pub fn fetch(path: &Path, url: &str, refspecs: &[String]) -> Result { let mut command = Command::new("git"); command .arg("-C") @@ -114,6 +114,5 @@ pub fn fetch(path: &Path, url: &str, refspecs: &[String]) -> Result<(), Error> { for refspec in refspecs { command.arg(refspec); } - run(command)?; - Ok(()) + run(command) } diff --git a/src/server.rs b/src/server.rs index 8fae60b..4b1fed1 100644 --- a/src/server.rs +++ b/src/server.rs @@ -44,7 +44,9 @@ fn open_repo( git::fetch_head(path, url)?; info!("Fetching refs for the first time (this may take a while)"); - git::fetch(path, url, refspecs)?; + let output = git::fetch(path, url, refspecs)?; + let stderr = String::from_utf8_lossy(&output.stderr); + info!("Fetched refs:\n{}", stderr.trim_end()); Ok(ThreadSafeRepository::open(path)?) } else { diff --git a/src/server/recurring/fetch.rs b/src/server/recurring/fetch.rs index b1f084d..e4f54f9 100644 --- a/src/server/recurring/fetch.rs +++ b/src/server/recurring/fetch.rs @@ -1,17 +1,22 @@ //! Update repo refs using the `git` binary. -use log::{info, warn}; +use log::{debug, info, warn}; use crate::{config::ServerConfig, git, server::Repo, somehow}; async fn inner(repo: Repo, url: &'static str, refspecs: &'static [String]) -> somehow::Result<()> { - tokio::task::spawn_blocking(move || git::fetch(repo.0.path(), url, refspecs)).await??; + let output = + tokio::task::spawn_blocking(move || git::fetch(repo.0.path(), url, refspecs)).await??; + let stderr = String::from_utf8_lossy(&output.stderr); + if !stderr.is_empty() { + info!("Fetched refs:\n{}", stderr.trim_end()); + } Ok(()) } pub(super) async fn update(config: &'static ServerConfig, repo: Repo) { if let Some(url) = &config.repo_fetch_url { - info!("Fetching refs from {url}"); + debug!("Fetching refs from {url}"); if let Err(e) = inner(repo, url, &config.repo_fetch_refspecs).await { warn!("Error fetching refs:\n{e:?}"); }