mirror of
https://github.com/martinvonz/jj.git
synced 2025-01-19 10:44:58 +00:00
fix: add support for fixing only some paths
This commit is contained in:
parent
3cd1fe4753
commit
78cbb513d1
3 changed files with 34 additions and 3 deletions
|
@ -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<RevisionArg>,
|
||||
/// Fix only these paths
|
||||
#[arg(value_hint = clap::ValueHint::AnyPath)]
|
||||
paths: Vec<String>,
|
||||
}
|
||||
|
||||
#[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?;
|
||||
|
|
|
@ -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:**
|
||||
|
||||
* `<PATHS>` — Fix only these paths
|
||||
|
||||
###### **Options:**
|
||||
|
||||
|
|
|
@ -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"]);
|
||||
|
|
Loading…
Reference in a new issue