From 67b1c54c2d82bc9b2a5876b00f77b849efc9eeae Mon Sep 17 00:00:00 2001 From: Jon Deibel Date: Thu, 5 Mar 2026 22:59:40 -0500 Subject: [PATCH 1/2] feat: add gw diff command with difftastic support --- src/cli.rs | 14 +++++++++ src/commands/diff.rs | 68 ++++++++++++++++++++++++++++++++++++++++++++ src/commands/mod.rs | 1 + src/main.rs | 4 ++- 4 files changed, 86 insertions(+), 1 deletion(-) create mode 100644 src/commands/diff.rs diff --git a/src/cli.rs b/src/cli.rs index afef55b..1e28a31 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -26,6 +26,8 @@ pub enum Commands { Switch(SwitchArgs), /// Show status of the current branch in its stack Status, + /// Show diff for the current branch's changes + Diff(DiffArgs), /// Show log of all stacks with branches and commits #[command(alias = "tree")] Log(TreeArgs), @@ -163,6 +165,18 @@ pub struct TreeArgs { pub pr: bool, } +// -- Diff -- + +#[derive(Args)] +pub struct DiffArgs { + /// Show diffstat summary instead of full diff + #[arg(long)] + pub stat: bool, + /// Use regular git diff instead of difftastic + #[arg(long)] + pub no_difftastic: bool, +} + // -- Config -- #[derive(Args)] diff --git a/src/commands/diff.rs b/src/commands/diff.rs new file mode 100644 index 0000000..1fe8164 --- /dev/null +++ b/src/commands/diff.rs @@ -0,0 +1,68 @@ +use anyhow::{bail, Result}; +use std::process::Command; + +use crate::context::Ctx; +use crate::ui; + +pub fn run(ctx: &Ctx, stat: bool, no_difftastic: bool) -> Result<()> { + let current = ctx.git.current_branch()?; + + let stack = match ctx.find_stack_for_branch(¤t)? { + Some(s) => s, + None => bail!( + "Branch '{current}' is not in any stack.\n\ + Use `gw adopt` to add it, or run `git diff` directly." + ), + }; + + // parent_of returns base_branch for root branches + let parent = stack.parent_of(¤t).unwrap(); + + let merge_base = ctx.git.merge_base(&parent, ¤t)?; + + let use_difft = !no_difftastic && difft_available(); + + if stat { + // --stat always uses regular git diff (difftastic doesn't support --stat) + let status = Command::new("git") + .args(["diff", "--stat", &merge_base, "HEAD"]) + .current_dir(ctx.git.repo_path()) + .status()?; + + if !status.success() { + bail!("git diff --stat failed"); + } + } else { + let mut cmd = Command::new("git"); + cmd.args(["diff", &merge_base, "HEAD"]) + .current_dir(ctx.git.repo_path()); + + if use_difft { + cmd.env("GIT_EXTERNAL_DIFF", "difft"); + } + + let status = cmd.status()?; + + if !status.success() && !use_difft { + bail!("git diff failed"); + } + } + + if !stat { + ui::info(&format!( + "Showing changes on '{}' since '{}'", + current, parent + )); + } + + Ok(()) +} + +fn difft_available() -> bool { + Command::new("difft") + .arg("--version") + .stdout(std::process::Stdio::null()) + .stderr(std::process::Stdio::null()) + .status() + .is_ok_and(|s| s.success()) +} diff --git a/src/commands/mod.rs b/src/commands/mod.rs index 74c79ae..6a72b13 100644 --- a/src/commands/mod.rs +++ b/src/commands/mod.rs @@ -2,6 +2,7 @@ pub mod adopt; pub mod branch; pub mod completions; pub mod config; +pub mod diff; pub mod mcp_server; pub mod mcp_setup; pub mod push; diff --git a/src/main.rs b/src/main.rs index eeeb5a5..649aef3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -37,7 +37,8 @@ fn main() -> Result<()> { Commands::Rebase(args) if args.cont || args.abort ) || matches!(&command, Commands::Log(_)) || matches!(&command, Commands::Switch(_)) - || matches!(&command, Commands::Status); + || matches!(&command, Commands::Status) + || matches!(&command, Commands::Diff(_)); if !allowed { let op = match prop_state.operation { @@ -56,6 +57,7 @@ fn main() -> Result<()> { match command { Commands::Status => commands::status::run(&ctx), + Commands::Diff(args) => commands::diff::run(&ctx, args.stat, args.no_difftastic), Commands::Stack(args) => commands::stack::run(args.command, &ctx), Commands::Branch(args) => commands::branch::run(args.command, &ctx), Commands::Adopt(args) => commands::adopt::run(args, &ctx), From da3f2d17e06a2b09aa9010979e8b312a054e4b57 Mon Sep 17 00:00:00 2001 From: Jon Deibel Date: Thu, 5 Mar 2026 23:02:47 -0500 Subject: [PATCH 2/2] feat: add difftastic as homebrew runtime dependency cargo-dist will include depends_on "difftastic" in the generated formula so brew users get it automatically. Shell installer users still get the graceful fallback to regular git diff. Co-Authored-By: Claude Opus 4.6 (1M context) --- Cargo.toml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Cargo.toml b/Cargo.toml index 5f486c8..d545784 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -42,3 +42,6 @@ targets = [ "x86_64-unknown-linux-gnu", "aarch64-unknown-linux-gnu", ] + +[workspace.metadata.dist.dependencies.homebrew] +difftastic = { stage = ["run"] }