Skip to content

Commit

Permalink
cli: diff: add --exclude flag
Browse files Browse the repository at this point in the history
  • Loading branch information
bryceberger committed Nov 24, 2024
1 parent 10c90a5 commit 98c09e5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <TABLE-NAME>` no longer removes a table (such as `[ui]`.)
Expand Down
8 changes: 8 additions & 0 deletions cli/src/commands/diff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ pub(crate) struct DiffArgs {
/// Restrict the diff to these paths
#[arg(value_hint = clap::ValueHint::AnyPath)]
paths: Vec<String>,
/// Exclude these paths from the diff
#[arg(short = 'x', long, value_hint = clap::ValueHint::AnyPath)]
exclude: Vec<String>,
#[command(flatten)]
format: DiffFormatArgs,
}
Expand All @@ -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<RevisionArg>| {
workspace_command.resolve_single_rev(ui, r.as_ref().unwrap_or(&RevisionArg::AT))
Expand Down

0 comments on commit 98c09e5

Please sign in to comment.