Skip to content

Commit

Permalink
cli: add pointer to the documentation in case of fileset syntax error
Browse files Browse the repository at this point in the history
  • Loading branch information
samueltardieu committed Oct 4, 2024
1 parent 6878b50 commit ab861e2
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 4 deletions.
1 change: 0 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

### Fixed bugs


## [0.22.0] - 2024-10-02

### Breaking changes
Expand Down
5 changes: 4 additions & 1 deletion cli/src/command_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -613,14 +613,17 @@ fn file_pattern_parse_error_hint(err: &FilePatternParseError) -> Option<String>

fn fileset_parse_error_hint(err: &FilesetParseError) -> Option<String> {
match err.kind() {
FilesetParseErrorKind::SyntaxError => Some(String::from(
"See https://martinvonz.github.io/jj/latest/filesets/ for filesets syntax, or for how \
to match file paths.",
)),
FilesetParseErrorKind::NoSuchFunction {
name: _,
candidates,
} => format_similarity_hint(candidates),
FilesetParseErrorKind::InvalidArguments { .. } | FilesetParseErrorKind::Expression(_) => {
find_source_parse_error_hint(&err)
}
_ => None,
}
}

Expand Down
25 changes: 25 additions & 0 deletions cli/tests/test_global_opts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,31 @@ fn test_bad_path() {
"###);
}

#[test]
fn test_invalid_filesets_looking_like_filepaths() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_ok(test_env.env_root(), &["git", "init", "repo"]);
let repo_path = test_env.env_root().join("repo");

let stderr = test_env.jj_cmd_failure(&repo_path, &["file", "show", "abc~"]);
insta::assert_snapshot!(stderr, @r#"
Error: Failed to parse fileset: Syntax error
Caused by: --> 1:5
|
1 | abc~
| ^---
|
= expected `~` or <primary>
Hint: See https://martinvonz.github.io/jj/latest/filesets/ for filesets syntax, or for how to match file paths.
"#);

test_env.add_config(r#"ui.allow-filesets=false"#);
let stderr = test_env.jj_cmd_failure(&repo_path, &["file", "show", "abc~"]);
insta::assert_snapshot!(stderr, @r#"
Error: No such path: abc~
"#);
}

#[test]
fn test_broken_repo_structure() {
let test_env = TestEnvironment::default();
Expand Down
5 changes: 3 additions & 2 deletions cli/tests/test_revset_output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ fn test_bad_function_call() {
"###);

let stderr = test_env.jj_cmd_failure(&repo_path, &["log", "-r", "files(not::a-fileset)"]);
insta::assert_snapshot!(stderr, @r###"
insta::assert_snapshot!(stderr, @r#"
Error: Failed to parse revset: In fileset expression
Caused by:
1: --> 1:7
Expand All @@ -156,7 +156,8 @@ fn test_bad_function_call() {
| ^---
|
= expected <identifier>, <string_literal>, or <raw_string_literal>
"###);
Hint: See https://martinvonz.github.io/jj/latest/filesets/ for filesets syntax, or for how to match file paths.
"#);

let stderr = test_env.jj_cmd_failure(&repo_path, &["log", "-r", r#"files(foo:"bar")"#]);
insta::assert_snapshot!(stderr, @r###"
Expand Down

0 comments on commit ab861e2

Please sign in to comment.