From 0f0f9ff9b4cce526ac39a4140a6400b1bd7c6368 Mon Sep 17 00:00:00 2001 From: cloudhead Date: Mon, 11 Mar 2024 18:05:18 +0100 Subject: [PATCH] helper: Check for missing canonical head Without the canonical head in the working copy, the next check will fail with a cryptic error. --- radicle-remote-helper/src/push.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/radicle-remote-helper/src/push.rs b/radicle-remote-helper/src/push.rs index c777610b..655a8037 100644 --- a/radicle-remote-helper/src/push.rs +++ b/radicle-remote-helper/src/push.rs @@ -96,6 +96,9 @@ pub enum Error { /// Patch is empty. #[error("patch commits are already included in the base branch")] EmptyPatch, + /// Missing canonical head. + #[error("the canonical head is missing from your working copy; please pull before pushing")] + MissingCanonicalHead(git::Oid), /// COB store error. #[error(transparent)] Cob(#[from] radicle::cob::store::Error), @@ -257,6 +260,13 @@ pub fn run( && delegates.contains(&Did::from(nid)) && delegates.len() > 1 { + if let Err(e) = working.find_commit(**canonical_oid) { + return if git::ext::is_not_found_err(&e) { + Err(Error::MissingCanonicalHead(*canonical_oid)) + } else { + Err(e.into()) + }; + } let head = working.find_reference(src.as_str())?; let head = head.peel_to_commit()?.id(); // Rollback is allowed and head is an ancestor of the canonical head.