From 82d190f64f8297944a10f2feb829b96b0ed53bb1 Mon Sep 17 00:00:00 2001 From: Slack Coder Date: Wed, 12 Apr 2023 14:10:13 -0500 Subject: [PATCH] cli: fetch if commmit missing when `rad merge`ing Reduce friction when merging patches by automatically fetching the Patch's commit head if its missing. The calls git directly due to difficulties fetch the revision anonymously with existing method. Its important to fetch the commit anonymously to remove dependency on how the local 'git remote's are configured. --- radicle-cli/src/commands/merge.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/radicle-cli/src/commands/merge.rs b/radicle-cli/src/commands/merge.rs index f584ac32..2513b7a0 100644 --- a/radicle-cli/src/commands/merge.rs +++ b/radicle-cli/src/commands/merge.rs @@ -177,6 +177,24 @@ pub fn run(options: Options, ctx: impl term::Context) -> anyhow::Result<()> { // let patch_commit = repo .find_annotated_commit(revision.head().into()) + .or_else(|e| match e.code() { + git::raw::ErrorCode::NotFound => { + // Avoid using git2 until 'rad://' supports fetching using an Oid as a refspec. + crate::git::git( + repo.path(), + [ + "fetch", + &git::Url::from(id) + .with_namespace(**patch.author().id()) + .to_string(), + &revision.head().to_string(), + ], + )?; + let c = repo.find_annotated_commit(revision.head().into())?; + Ok(c) + } + _ => Err(anyhow::Error::from(e)), + }) .context("patch head not found in local repository")?; let (merge, _merge_pref) = repo.merge_analysis(&[&patch_commit])?;