Radish alpha
r
rad:z39mP9rQAaGmERfUMPULfPUi473tY
Radicle terminal user interface
Radicle
Git
patch/list: Use `git diff` instead of `rad diff`
Erik Kundt committed 4 months ago
commit 2c3e2909e0e8373e10c566c781631dea9d963abf
parent 27b3fd7
2 files changed +43 -5
modified bin/commands/patch.rs
@@ -9,6 +9,7 @@ use anyhow::anyhow;

use radicle::cob::ObjectId;
use radicle::identity::RepoId;
+
use radicle::patch::cache::Patches;
use radicle::patch::{Patch, Revision, RevisionId, Status};
use radicle::prelude::Did;
use radicle::storage::git::Repository;
@@ -335,11 +336,14 @@ pub async fn run(options: Options, ctx: impl radicle_cli::terminal::Context) ->
                            )?;
                        }
                        PatchOperation::Diff { id } => {
-
                            terminal::run_rad(
-
                                Some("patch"),
-
                                &["diff".into(), id.to_string().into()],
-
                                Quiet::No,
-
                            )?;
+
                            let repo = profile.storage.repository(rid)?;
+
                            let cache = profile.patches(&repo)?;
+
                            let patch = cache
+
                                .get(&id)?
+
                                .ok_or_else(|| anyhow!("unknown patch '{id}'"))?;
+
                            let range = format!("{}..{}", patch.base(), patch.head());
+

+
                            terminal::run_git(Some("diff"), &[range.into()], Quiet::No)?;
                        }
                        PatchOperation::Checkout { id } => {
                            terminal::run_rad(
modified bin/terminal.rs
@@ -25,6 +25,14 @@ pub enum ForwardError {
    Io(#[from] std::io::Error),
}

+
#[derive(Error, Debug)]
+
pub enum GitError {
+
    #[error("an error occured while executing 'git'")]
+
    Internal,
+
    #[error("an I/O error occured while trying to forward command to 'git': {0}")]
+
    Io(#[from] std::io::Error),
+
}
+

fn _run_rad(args: &[OsString], quiet: Quiet) -> Result<(), ForwardError> {
    let status = match quiet {
        Quiet::Yes => process::Command::new("rad")
@@ -56,6 +64,32 @@ pub fn run_rad(command: Option<&str>, args: &[OsString], quiet: Quiet) -> Result
    _run_rad(&args, quiet)
}

+
pub fn run_git(command: Option<&str>, args: &[OsString], quiet: Quiet) -> Result<(), GitError> {
+
    let args = if let Some(command) = command {
+
        [vec![command.into()], args.to_vec()].concat()
+
    } else {
+
        args.to_vec()
+
    };
+

+
    let status = match quiet {
+
        Quiet::Yes => process::Command::new("git")
+
            .args(args)
+
            .stdout(process::Stdio::null())
+
            .stderr(process::Stdio::null())
+
            .status(),
+
        Quiet::No => process::Command::new("git").args(args).status(),
+
    };
+
    match status {
+
        Ok(status) => {
+
            if !status.success() {
+
                return Err(GitError::Internal);
+
            }
+
            Ok(())
+
        }
+
        Err(err) => Err(err.into()),
+
    }
+
}
+

pub fn run_command_args<A, C>(help: Help, cmd: C, args: Vec<OsString>) -> !
where
    A: Args,