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.
This commit is contained in:
Slack Coder 2023-04-12 14:10:13 -05:00 committed by Alexis Sellier
parent 3e87e5f9eb
commit 82d190f64f
No known key found for this signature in database
1 changed files with 18 additions and 0 deletions

View File

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