diff --git a/CHANGELOG.md b/CHANGELOG.md index a703a6dfe2..9a06c266b2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * The default template alias `builtin_log_root(change_id: ChangeId, commit_id: CommitId)` was replaced by `format_root_commit(root: Commit)`. +* Path arguments are now parsed as ["fileset" expressions](docs/filesets.md). + File name containing meta characters or whitespace will need to be escaped. + Example: `jj diff '"File name with space"'`. + ### New features * The list of conflicted paths is printed whenever the working copy changes. diff --git a/cli/src/cli_util.rs b/cli/src/cli_util.rs index 32cc17c5cb..e7d94d5bf0 100644 --- a/cli/src/cli_util.rs +++ b/cli/src/cli_util.rs @@ -36,7 +36,7 @@ use indexmap::{IndexMap, IndexSet}; use itertools::Itertools; use jj_lib::backend::{ChangeId, CommitId, MergedTreeId, TreeValue}; use jj_lib::commit::Commit; -use jj_lib::fileset::{FilePattern, FilesetExpression, FilesetParseContext}; +use jj_lib::fileset::{FilesetExpression, FilesetParseContext}; use jj_lib::git_backend::GitBackend; use jj_lib::gitignore::{GitIgnoreError, GitIgnoreFile}; use jj_lib::hex_util::to_reverse_hex; @@ -657,14 +657,7 @@ impl WorkspaceCommandHelper { if values.is_empty() { Ok(FilesetExpression::all()) } else { - let ctx = self.fileset_parse_context(); - let expressions = values - .iter() - .map(|v| FilePattern::parse(&ctx, v)) - .map_ok(FilesetExpression::pattern) - .try_collect() - .map_err(user_error)?; - Ok(FilesetExpression::union_all(expressions)) + self.parse_union_filesets(values) } } diff --git a/cli/tests/test_global_opts.rs b/cli/tests/test_global_opts.rs index cf358b9b90..44a814a73f 100644 --- a/cli/tests/test_global_opts.rs +++ b/cli/tests/test_global_opts.rs @@ -403,8 +403,16 @@ fn test_color_ui_messages() { // error source let stderr = test_env.jj_cmd_failure(&repo_path, &["log", ".."]); insta::assert_snapshot!(stderr.replace('\\', "/"), @r###" - Error: Path ".." is not in the repo "." - Caused by: Invalid component ".." in repo-relative path "../" + Error: Failed to parse fileset: Invalid file pattern + Caused by: + 1:  --> 1:1 +  | + 1 | .. +  | ^^ +  | +  = Invalid file pattern + 2: Path ".." is not in the repo "." + 3: Invalid component ".." in repo-relative path "../" "###); // warning diff --git a/cli/tests/test_log_command.rs b/cli/tests/test_log_command.rs index 14dd87ee30..bef3c6d71f 100644 --- a/cli/tests/test_log_command.rs +++ b/cli/tests/test_log_command.rs @@ -822,6 +822,17 @@ fn test_log_filtered_by_path() { A file2 "###); + // empty revision is filtered out by "all()" fileset. + let stdout = test_env.jj_cmd_success(&repo_path, &["log", "-Tdescription", "-s", "all()"]); + insta::assert_snapshot!(stdout, @r###" + @ second + │ M file1 + │ A file2 + ◉ first + │ A file1 + ~ + "###); + // "root:" is resolved relative to the workspace root. let stdout = test_env.jj_cmd_success( test_env.env_root(), diff --git a/docs/filesets.md b/docs/filesets.md index b9bccaf079..c833c2be8b 100644 --- a/docs/filesets.md +++ b/docs/filesets.md @@ -35,3 +35,17 @@ You can also specify patterns by using functions. * `all()`: Matches everything. * `none()`: Matches nothing. + +## Examples + +Show diff excluding `Cargo.lock`. + +``` +jj diff '~Cargo.lock' +``` + +Split a revision in two, putting `foo` into the second commit. + +``` +jj split '~foo' +``` diff --git a/lib/src/fileset.rs b/lib/src/fileset.rs index 31368ae28d..2cef3f50a9 100644 --- a/lib/src/fileset.rs +++ b/lib/src/fileset.rs @@ -60,17 +60,6 @@ pub enum FilePattern { } impl FilePattern { - /// Parses the given `input` string as a file pattern. - // TODO: If we decide to parse any file argument as a fileset expression, - // this function can be removed. - pub fn parse(ctx: &FilesetParseContext, input: &str) -> Result { - if let Some((kind, pat)) = input.split_once(':') { - Self::from_str_kind(ctx, pat, kind) - } else { - Self::cwd_prefix_path(ctx, input) - } - } - /// Parses the given `input` string as pattern of the specified `kind`. pub fn from_str_kind( ctx: &FilesetParseContext,