diff --git a/cli/src/commands/fix.rs b/cli/src/commands/fix.rs index 795bd0303..6112e0ef8 100644 --- a/cli/src/commands/fix.rs +++ b/cli/src/commands/fix.rs @@ -20,7 +20,6 @@ use std::sync::mpsc::channel; use futures::StreamExt; use itertools::Itertools; use jj_lib::backend::{BackendError, BackendResult, CommitId, FileId, TreeValue}; -use jj_lib::matchers::EverythingMatcher; use jj_lib::merged_tree::MergedTreeBuilder; use jj_lib::repo::Repo; use jj_lib::repo_path::RepoPathBuf; @@ -69,6 +68,9 @@ pub(crate) struct FixArgs { /// Fix files in the specified revision(s) and their descendants #[arg(long, short)] source: Vec, + /// Fix only these paths + #[arg(value_hint = clap::ValueHint::AnyPath)] + paths: Vec, } #[instrument(skip_all)] @@ -87,6 +89,9 @@ pub(crate) fn cmd_fix( .evaluate_to_commit_ids()? .collect(); workspace_command.check_rewritable(root_commits.iter())?; + let matcher = workspace_command + .parse_file_patterns(&args.paths)? + .to_matcher(); let mut tx = workspace_command.start_transaction(); @@ -127,7 +132,7 @@ pub(crate) fn cmd_fix( // Also fix any new paths that were changed in this commit. let tree = commit.tree()?; let parent_tree = commit.parent_tree(tx.repo())?; - let mut diff_stream = parent_tree.diff_stream(&tree, &EverythingMatcher); + let mut diff_stream = parent_tree.diff_stream(&tree, &matcher); async { while let Some((repo_path, diff)) = diff_stream.next().await { let (_before, after) = diff?; diff --git a/cli/tests/cli-reference@.md.snap b/cli/tests/cli-reference@.md.snap index eeb57b5cc..8b074b21e 100644 --- a/cli/tests/cli-reference@.md.snap +++ b/cli/tests/cli-reference@.md.snap @@ -790,7 +790,11 @@ tool-command = ["rustfmt", "--emit", "stdout"] And then run the command `jj fix -s @`. -**Usage:** `jj fix [OPTIONS]` +**Usage:** `jj fix [OPTIONS] [PATHS]...` + +###### **Arguments:** + +* `` — Fix only these paths ###### **Options:** diff --git a/cli/tests/test_fix_command.rs b/cli/tests/test_fix_command.rs index e9a67e9bf..2db3e696c 100644 --- a/cli/tests/test_fix_command.rs +++ b/cli/tests/test_fix_command.rs @@ -175,6 +175,28 @@ fn test_fix_empty_file() { insta::assert_snapshot!(content, @""); } +#[test] +fn test_fix_some_paths() { + let (test_env, repo_path) = init_with_fake_formatter(&["--uppercase"]); + std::fs::write(repo_path.join("file1"), "foo").unwrap(); + std::fs::write(repo_path.join("file2"), "bar").unwrap(); + + let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["fix", "-s", "@", "file1"]); + insta::assert_snapshot!(stdout, @""); + insta::assert_snapshot!(stderr, @r###" + Fixed 1 commits of 1 checked. + Working copy now at: qpvuntsm 3f72f723 (no description set) + Parent commit : zzzzzzzz 00000000 (empty) (no description set) + Added 0 files, modified 1 files, removed 0 files + "###); + let content = test_env.jj_cmd_success(&repo_path, &["print", "file1"]); + insta::assert_snapshot!(content, @r###" + FOO + "###); + let content = test_env.jj_cmd_success(&repo_path, &["print", "file2"]); + insta::assert_snapshot!(content, @"bar"); +} + #[test] fn test_fix_cyclic() { let (test_env, repo_path) = init_with_fake_formatter(&["--reverse"]);