From 3e05939d14f16a4ccc20840849d09903f684bb51 Mon Sep 17 00:00:00 2001 From: Alexis Sellier Date: Thu, 13 Apr 2023 12:42:50 +0200 Subject: [PATCH] node: Don't fail fetch for existing repositories If `git-fetch` returns a non-zero code on exit, we keep going in the case of an existing repository. The reason is that `git-fetch` will return an error code if any ref is rejected during the fetch. But this can happen if someone pushes conflicting `rad/sigrefs` branches for example, and the node already has a copy of that branch. --- radicle-node/src/worker.rs | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/radicle-node/src/worker.rs b/radicle-node/src/worker.rs index f4199fc3..460f8f5d 100644 --- a/radicle-node/src/worker.rs +++ b/radicle-node/src/worker.rs @@ -245,10 +245,22 @@ impl Worker { &mut channels, ) { Ok(()) => log::debug!(target: "worker", "Initial fetch for {rid} exited successfully"), - Err(e) => { - log::error!(target: "worker", "Initial fetch for {rid} failed: {e}"); - return Err(e); - } + Err(e) => match (&staging.repo, e) { + // When fetching, if the error comes from `git-fetch` returning an error, we + // keep going because it could be due to a rejected ref (eg. on `rad/sigrefs`), + // and that is non-fatal. + (fetch::StagedRepository::Fetching(_), e @ FetchError::CommandFailed { .. }) => { + log::warn!(target: "worker", "Initial fetch for {rid} returned an error: {e}"); + log::warn!(target: "worker", "It's possible that some of the refs were rejected.."); + } + // When cloning, any error is fatal, since we'll end up with an empty repository. + // Likewise, when fetching, if the error is coming from some other place, we + // abort the fetch. + (fetch::StagedRepository::Cloning(_) | fetch::StagedRepository::Fetching(_), e) => { + log::error!(target: "worker", "Initial fetch for {rid} failed: {e}"); + return Err(e); + } + }, } let staging = staging.into_final()?;