From 98c09e54e2c6ca713a2a08b7ec8b732e15addd75 Mon Sep 17 00:00:00 2001 From: Bryce Berger Date: Sat, 23 Nov 2024 23:57:11 -0500 Subject: [PATCH] cli: diff: add `--exclude` flag --- CHANGELOG.md | 4 ++++ cli/src/commands/diff.rs | 8 ++++++++ 2 files changed, 12 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c2b040bc35..1680da43ff 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -71,6 +71,10 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). "diff3" conflict style, meaning it is more likely to work with external tools, but it doesn't support conflicts with more than 2 sides. +* `jj diff` now accepts a `-x` / `--exclude` flag (can be repeated), to remove + files from the view. Explicitly excluded files take precedence over included + files. + ### Fixed bugs * `jj config unset ` no longer removes a table (such as `[ui]`.) diff --git a/cli/src/commands/diff.rs b/cli/src/commands/diff.rs index 446c796c49..d708da4fde 100644 --- a/cli/src/commands/diff.rs +++ b/cli/src/commands/diff.rs @@ -59,6 +59,9 @@ pub(crate) struct DiffArgs { /// Restrict the diff to these paths #[arg(value_hint = clap::ValueHint::AnyPath)] paths: Vec, + /// Exclude these paths from the diff + #[arg(short = 'x', long, value_hint = clap::ValueHint::AnyPath)] + exclude: Vec, #[command(flatten)] format: DiffFormatArgs, } @@ -72,6 +75,11 @@ pub(crate) fn cmd_diff( let workspace_command = command.workspace_helper(ui)?; let repo = workspace_command.repo(); let fileset_expression = workspace_command.parse_file_patterns(ui, &args.paths)?; + let fileset_expression = if args.exclude.is_empty() { + fileset_expression + } else { + fileset_expression.difference(workspace_command.parse_file_patterns(ui, &args.exclude)?) + }; let matcher = fileset_expression.to_matcher(); let resolve_revision = |r: &Option| { workspace_command.resolve_single_rev(ui, r.as_ref().unwrap_or(&RevisionArg::AT))