remote-helper: Accept revision for `patch.base`

When specifying a `patch.base` to point to for stacking patches, it's
useful to accept any kind of revspec, e.g. `HEAD^`.

Change the argument parsing to use the `Rev` type instead, and change
the `rad-patch-ahead-behind` to use `HEAD^` to test the example usage.

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
This commit is contained in:
Fintan Halpenny 2023-10-24 13:56:20 +01:00 committed by cloudhead
parent 199fa07a79
commit 90f3a37a08
No known key found for this signature in database
3 changed files with 10 additions and 5 deletions

View File

@ -123,7 +123,7 @@ If we want to instead create a "stacked" patch, we can do so with the
`patch.base` push option: `patch.base` push option:
``` (stderr) ``` (stderr)
$ git push -o patch.message="Add Mel #2" -o patch.base=5c88a79d75f5c2b4cc51ee6f163d2db91ee198d7 rad HEAD:refs/patches $ git push -o patch.message="Add Mel #2" -o patch.base=HEAD^ rad HEAD:refs/patches
✓ Patch 11ab7fbec82c3aed393d7a696d6b3c7714735056 opened ✓ Patch 11ab7fbec82c3aed393d7a696d6b3c7714735056 opened
To rad://z42hL2jL4XNk6K8oHQaSWfMgCL7ji/z6MknSLrJoTcukLrE435hVNQT4JUhbvWLX4kUzqkEStBU8Vi To rad://z42hL2jL4XNk6K8oHQaSWfMgCL7ji/z6MknSLrJoTcukLrE435hVNQT4JUhbvWLX4kUzqkEStBU8Vi
* [new reference] HEAD -> refs/patches * [new reference] HEAD -> refs/patches

View File

@ -13,6 +13,7 @@ use std::str::FromStr;
use std::time; use std::time;
use std::{env, io}; use std::{env, io};
use radicle_cli::git::Rev;
use thiserror::Error; use thiserror::Error;
use radicle::git; use radicle::git;
@ -25,6 +26,9 @@ use radicle_cli::terminal as cli;
#[derive(Debug, Error)] #[derive(Debug, Error)]
pub enum Error { pub enum Error {
/// Failed to parse `base`.
#[error("failed to parse base revision: {0}")]
Base(Box<dyn std::error::Error>),
/// Remote repository not found (or empty). /// Remote repository not found (or empty).
#[error("remote repository `{0}` not found")] #[error("remote repository `{0}` not found")]
RepositoryNotFound(PathBuf), RepositoryNotFound(PathBuf),
@ -70,7 +74,7 @@ pub struct Options {
/// Open patch in draft mode. /// Open patch in draft mode.
draft: bool, draft: bool,
/// Patch base to use, when opening or updating a patch. /// Patch base to use, when opening or updating a patch.
base: Option<git::Oid>, base: Option<Rev>,
/// Patch message. /// Patch message.
message: cli::patch::Message, message: cli::patch::Message,
} }
@ -138,7 +142,8 @@ pub fn run(profile: radicle::Profile) -> Result<(), Error> {
opts.message.append(val); opts.message.append(val);
} }
"patch.base" => { "patch.base" => {
let base = val.parse()?; let base = cli::args::rev(&val.into())
.map_err(|e| Error::Base(e.into()))?;
opts.base = Some(base); opts.base = Some(base);
} }
_ => { _ => {

View File

@ -309,7 +309,7 @@ fn patch_open<G: Signer>(
let (_, target) = stored.canonical_head()?; let (_, target) = stored.canonical_head()?;
let head = commit.id().into(); let head = commit.id().into();
let base = if let Some(base) = opts.base { let base = if let Some(base) = opts.base {
base base.resolve(working)?
} else { } else {
stored.merge_base(&target, &head)? stored.merge_base(&target, &head)?
}; };
@ -425,7 +425,7 @@ fn patch_update<G: Signer>(
let (_, target) = stored.canonical_head()?; let (_, target) = stored.canonical_head()?;
let head: git::Oid = commit.id().into(); let head: git::Oid = commit.id().into();
let base = if let Some(base) = opts.base { let base = if let Some(base) = opts.base {
base base.resolve(working)?
} else { } else {
stored.merge_base(&target, &head)? stored.merge_base(&target, &head)?
}; };