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:
parent
199fa07a79
commit
90f3a37a08
|
|
@ -123,7 +123,7 @@ If we want to instead create a "stacked" patch, we can do so with the
|
|||
`patch.base` push option:
|
||||
|
||||
``` (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
|
||||
To rad://z42hL2jL4XNk6K8oHQaSWfMgCL7ji/z6MknSLrJoTcukLrE435hVNQT4JUhbvWLX4kUzqkEStBU8Vi
|
||||
* [new reference] HEAD -> refs/patches
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ use std::str::FromStr;
|
|||
use std::time;
|
||||
use std::{env, io};
|
||||
|
||||
use radicle_cli::git::Rev;
|
||||
use thiserror::Error;
|
||||
|
||||
use radicle::git;
|
||||
|
|
@ -25,6 +26,9 @@ use radicle_cli::terminal as cli;
|
|||
|
||||
#[derive(Debug, 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).
|
||||
#[error("remote repository `{0}` not found")]
|
||||
RepositoryNotFound(PathBuf),
|
||||
|
|
@ -70,7 +74,7 @@ pub struct Options {
|
|||
/// Open patch in draft mode.
|
||||
draft: bool,
|
||||
/// Patch base to use, when opening or updating a patch.
|
||||
base: Option<git::Oid>,
|
||||
base: Option<Rev>,
|
||||
/// Patch message.
|
||||
message: cli::patch::Message,
|
||||
}
|
||||
|
|
@ -138,7 +142,8 @@ pub fn run(profile: radicle::Profile) -> Result<(), Error> {
|
|||
opts.message.append(val);
|
||||
}
|
||||
"patch.base" => {
|
||||
let base = val.parse()?;
|
||||
let base = cli::args::rev(&val.into())
|
||||
.map_err(|e| Error::Base(e.into()))?;
|
||||
opts.base = Some(base);
|
||||
}
|
||||
_ => {
|
||||
|
|
|
|||
|
|
@ -309,7 +309,7 @@ fn patch_open<G: Signer>(
|
|||
let (_, target) = stored.canonical_head()?;
|
||||
let head = commit.id().into();
|
||||
let base = if let Some(base) = opts.base {
|
||||
base
|
||||
base.resolve(working)?
|
||||
} else {
|
||||
stored.merge_base(&target, &head)?
|
||||
};
|
||||
|
|
@ -425,7 +425,7 @@ fn patch_update<G: Signer>(
|
|||
let (_, target) = stored.canonical_head()?;
|
||||
let head: git::Oid = commit.id().into();
|
||||
let base = if let Some(base) = opts.base {
|
||||
base
|
||||
base.resolve(working)?
|
||||
} else {
|
||||
stored.merge_base(&target, &head)?
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in New Issue