mirror of
https://seed.radicle.dev/rad:z3gqcJUoA1n9HaHKufZs5FCSGazv5.git
synced 2026-11-29 05:50:31 +08:00
Changes the `Error::WithHint::hint` field to use a `String` type instead of `&'static str`. This allows the caller to provide extra hint information. To make it easier to use an `Error::with_hint` constructor is added.
52 lines
1.2 KiB
Rust
52 lines
1.2 KiB
Rust
use std::process;
|
|
|
|
use radicle::cob::patch;
|
|
use radicle::git;
|
|
use radicle::storage::git::Repository;
|
|
|
|
use crate::terminal as term;
|
|
use crate::terminal::Error;
|
|
|
|
use super::*;
|
|
|
|
fn show_patch_diff(patch: &patch::Patch, stored: &Repository) -> anyhow::Result<()> {
|
|
let (from, to) = patch.range()?;
|
|
let range = format!("{from}..{to}");
|
|
|
|
process::Command::new("git")
|
|
.current_dir(stored.path())
|
|
.args(["log", "--patch", &range])
|
|
.stdout(process::Stdio::inherit())
|
|
.stderr(process::Stdio::inherit())
|
|
.spawn()?
|
|
.wait()?;
|
|
|
|
Ok(())
|
|
}
|
|
|
|
pub fn run(
|
|
patch_id: &PatchId,
|
|
diff: bool,
|
|
verbose: bool,
|
|
profile: &Profile,
|
|
stored: &Repository,
|
|
workdir: Option<&git::raw::Repository>,
|
|
) -> anyhow::Result<()> {
|
|
let patches = term::cob::patches(profile, stored)?;
|
|
let Some(patch) = patches
|
|
.get(patch_id)
|
|
.map_err(|e| Error::with_hint(e, "reset the cache with `rad patch cache` and try again"))?
|
|
else {
|
|
anyhow::bail!("Patch `{patch_id}` not found");
|
|
};
|
|
|
|
term::patch::show(&patch, patch_id, verbose, stored, workdir, profile)?;
|
|
|
|
if diff {
|
|
term::blank();
|
|
show_patch_diff(&patch, stored)?;
|
|
term::blank();
|
|
}
|
|
Ok(())
|
|
}
|