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.
This commit is contained in:
Alexis Sellier 2023-04-13 12:42:50 +02:00
parent 18616a16bd
commit 3e05939d14
No known key found for this signature in database
1 changed files with 16 additions and 4 deletions

View File

@ -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()?;