Radish alpha
h
Radicle Heartwood Protocol & Stack
Radicle
Git (anonymous pull)
Log in to clone via SSH
cli/diff: Remove
✗ CI failure Lorenz Leutgeb committed 7 months ago
commit 2695cb2a4044bc5ec18c9724f6e6bc1284e8ef52
parent ee49e28766ce7c703b95e22d177cce046072f03d
1 passed 1 failed 1 pending (3 total) View logs
5 files changed +29 -186
modified crates/radicle-cli/examples/rad-patch-diff.md
@@ -11,13 +11,13 @@ $ git push rad HEAD:refs/patches
```
```
$ rad patch diff 147309e
-
╭───────────────────────────╮
-
│ README.md +1 ❲created❳    │
-
├───────────────────────────┤
-
│ @@ -0,0 +1,1 @@           │
-
│      1     + Hello World! │
-
╰───────────────────────────╯
-

+
diff --git a/README.md b/README.md
+
new file mode 100644
+
index 0000000..980a0d5
+
--- /dev/null
+
+++ b/README.md
+
@@ -0,0 +1 @@
+
+Hello World!
```

If we add another file and update the patch, we can see it in the diff.
@@ -32,20 +32,20 @@ $ git push -f
```
```
$ rad patch diff 147309e
-
╭─────────────────────────────╮
-
│ RADICLE.md +1 ❲created❳     │
-
├─────────────────────────────┤
-
│ @@ -0,0 +1,1 @@             │
-
│      1     + Hello Radicle! │
-
╰─────────────────────────────╯
-

-
╭─────────────────────────────╮
-
│ README.md +1 ❲created❳      │
-
├─────────────────────────────┤
-
│ @@ -0,0 +1,1 @@             │
-
│      1     + Hello World!   │
-
╰─────────────────────────────╯
-

+
diff --git a/RADICLE.md b/RADICLE.md
+
new file mode 100644
+
index 0000000..e517184
+
--- /dev/null
+
+++ b/RADICLE.md
+
@@ -0,0 +1 @@
+
+Hello Radicle!
+
diff --git a/README.md b/README.md
+
new file mode 100644
+
index 0000000..980a0d5
+
--- /dev/null
+
+++ b/README.md
+
@@ -0,0 +1 @@
+
+Hello World!
```

Buf if we only want to see the changes from the first revision, we can do that
@@ -53,11 +53,11 @@ too.

```
$ rad patch diff 147309e --revision 147309e
-
╭───────────────────────────╮
-
│ README.md +1 ❲created❳    │
-
├───────────────────────────┤
-
│ @@ -0,0 +1,1 @@           │
-
│      1     + Hello World! │
-
╰───────────────────────────╯
-

+
diff --git a/README.md b/README.md
+
new file mode 100644
+
index 0000000..980a0d5
+
--- /dev/null
+
+++ b/README.md
+
@@ -0,0 +1 @@
+
+Hello World!
```
modified crates/radicle-cli/src/commands.rs
@@ -6,7 +6,6 @@ pub mod clone;
pub mod cob;
pub mod config;
pub mod debug;
-
pub mod diff;
pub mod follow;
pub mod fork;
pub mod help;
deleted crates/radicle-cli/src/commands/diff.rs
@@ -1,153 +0,0 @@
-
use std::ffi::OsString;
-

-
use anyhow::anyhow;
-

-
use radicle::git;
-
use radicle::rad;
-
use radicle_surf as surf;
-

-
use crate::git::pretty_diff::ToPretty as _;
-
use crate::git::Rev;
-
use crate::terminal as term;
-
use crate::terminal::args::{Args, Error, Help};
-
use crate::terminal::highlight::Highlighter;
-

-
pub const HELP: Help = Help {
-
    name: "diff",
-
    description: "Show changes between commits",
-
    version: env!("RADICLE_VERSION"),
-
    usage: r#"
-
Usage
-

-
    rad diff [<commit>] [--staged] [<option>...]
-
    rad diff <commit> [<commit>] [<option>...]
-

-
    This command is meant to operate as closely as possible to `git diff`,
-
    except its output is optimized for human-readability.
-

-
Options
-

-
    --unified, -U   Context lines to show (default: 5)
-
    --staged        View staged changes
-
    --color         Force color output
-
    --help          Print help
-
"#,
-
};
-

-
pub struct Options {
-
    pub commits: Vec<Rev>,
-
    pub staged: bool,
-
    pub unified: usize,
-
    pub color: bool,
-
}
-

-
impl Args for Options {
-
    fn from_args(args: Vec<OsString>) -> anyhow::Result<(Self, Vec<OsString>)> {
-
        use lexopt::prelude::*;
-

-
        let mut parser = lexopt::Parser::from_args(args);
-
        let mut commits = Vec::new();
-
        let mut staged = false;
-
        let mut unified = 5;
-
        let mut color = false;
-

-
        while let Some(arg) = parser.next()? {
-
            match arg {
-
                Long("unified") | Short('U') => {
-
                    let val = parser.value()?;
-
                    unified = term::args::number(&val)?;
-
                }
-
                Long("staged") | Long("cached") => staged = true,
-
                Long("color") => color = true,
-
                Long("help") | Short('h') => return Err(Error::Help.into()),
-
                Value(val) => {
-
                    let rev = term::args::rev(&val)?;
-

-
                    commits.push(rev);
-
                }
-
                _ => anyhow::bail!(arg.unexpected()),
-
            }
-
        }
-

-
        Ok((
-
            Options {
-
                commits,
-
                staged,
-
                unified,
-
                color,
-
            },
-
            vec![],
-
        ))
-
    }
-
}
-

-
pub fn run(options: Options, _ctx: impl term::Context) -> anyhow::Result<()> {
-
    crate::warning::deprecated("rad diff", "git diff");
-

-
    let repo = rad::repo()?;
-
    let oids = options
-
        .commits
-
        .into_iter()
-
        .map(|rev| {
-
            repo.revparse_single(rev.as_str())
-
                .map_err(|e| anyhow!("unknown object {rev}: {e}"))
-
                .and_then(|o| {
-
                    o.into_commit()
-
                        .map_err(|_| anyhow!("object {rev} is not a commit"))
-
                })
-
        })
-
        .collect::<Result<Vec<_>, _>>()?;
-

-
    let mut opts = git::raw::DiffOptions::new();
-
    opts.patience(true)
-
        .minimal(true)
-
        .context_lines(options.unified as u32);
-

-
    let mut find_opts = git::raw::DiffFindOptions::new();
-
    find_opts.exact_match_only(true);
-
    find_opts.all(true);
-

-
    let mut diff = match oids.as_slice() {
-
        [] => {
-
            if options.staged {
-
                let head = repo.head()?.peel_to_tree()?;
-
                // HEAD vs. index.
-
                repo.diff_tree_to_index(Some(&head), None, Some(&mut opts))
-
            } else {
-
                // Working tree vs. index.
-
                repo.diff_index_to_workdir(None, None)
-
            }
-
        }
-
        [commit] => {
-
            let commit = commit.tree()?;
-
            if options.staged {
-
                // Commit vs. index.
-
                repo.diff_tree_to_index(Some(&commit), None, Some(&mut opts))
-
            } else {
-
                // Commit vs. working tree.
-
                repo.diff_tree_to_workdir(Some(&commit), Some(&mut opts))
-
            }
-
        }
-
        [left, right] => {
-
            // Commit vs. commit.
-
            let left = left.tree()?;
-
            let right = right.tree()?;
-

-
            repo.diff_tree_to_tree(Some(&left), Some(&right), Some(&mut opts))
-
        }
-
        _ => {
-
            anyhow::bail!("Too many commits given. See `rad diff --help` for usage.");
-
        }
-
    }?;
-
    diff.find_similar(Some(&mut find_opts))?;
-

-
    term::Paint::force(options.color);
-

-
    let diff = surf::diff::Diff::try_from(diff)?;
-
    let mut hi = Highlighter::default();
-
    let pretty = diff.pretty(&mut hi, &(), &repo);
-

-
    crate::pager::run(pretty)?;
-

-
    Ok(())
-
}
modified crates/radicle-cli/src/commands/patch/diff.rs
@@ -25,7 +25,7 @@ pub fn run(
    };
    let (from, to) = revision.range();

-
    process::Command::new("rad")
+
    process::Command::new("git")
        .current_dir(stored.path())
        .args(["diff", from.to_string().as_str(), to.to_string().as_str()])
        .stdout(process::Stdio::inherit())
modified crates/radicle-cli/src/main.rs
@@ -196,9 +196,6 @@ pub(crate) fn run_other(exe: &str, args: &[OsString]) -> Result<(), Option<anyho
        "config" => {
            term::run_command_args::<config::Options, _>(config::HELP, config::run, args.to_vec());
        }
-
        "diff" => {
-
            term::run_command_args::<diff::Options, _>(diff::HELP, diff::run, args.to_vec());
-
        }
        "debug" => {
            term::run_command_args::<debug::Options, _>(debug::HELP, debug::run, args.to_vec());
        }