diff --git a/cli/tests/test_diff_command.rs b/cli/tests/test_diff_command.rs index c646c802ad..304374d216 100644 --- a/cli/tests/test_diff_command.rs +++ b/cli/tests/test_diff_command.rs @@ -204,7 +204,7 @@ fn test_diff_basic() { "diff", "--config-toml=ui.allow-filesets=true", "-s", - r#"glob:"file[12]""#, + "glob:file[12]", ], ); insta::assert_snapshot!(stdout, @r###" diff --git a/docs/filesets.md b/docs/filesets.md index 567aec0b1c..6a1c7bf67e 100644 --- a/docs/filesets.md +++ b/docs/filesets.md @@ -21,6 +21,11 @@ if the expression has no operators nor function calls. For example: * `jj diff '~"Foo Bar"'` (both shell and inner quotes are required) * `jj diff '"Foo(1)"'` (both shell and inner quotes are required) +Glob characters aren't considered meta characters, but shell quotes are still +required: + +* `jj diff '~glob:**/*.rs'` + [string-literals]: templates.md#string-literals ## File patterns diff --git a/lib/src/fileset.pest b/lib/src/fileset.pest index e8b1488b95..bc84aa4e2f 100644 --- a/lib/src/fileset.pest +++ b/lib/src/fileset.pest @@ -16,22 +16,21 @@ whitespace = _{ " " | "\t" | "\r" | "\n" | "\x0c" } // XID_CONTINUE: https://www.unicode.org/reports/tr31/#Default_Identifier_Syntax // +, -, ., @, _: commonly used in file name including "." and ".." +// *, ?, [, ]: glob characters (not extended glob) // /: path separator // \: path separator (Windows) -// TODO: accept glob characters as identifier? identifier = @{ - (XID_CONTINUE | "+" | "-" | "." | "@" | "_" | "/" | "\\")+ + (XID_CONTINUE | "+" | "-" | "." | "@" | "_" | "*" | "?" | "[" | "]" | "/" | "\\")+ } strict_identifier_part = @{ (ASCII_ALPHANUMERIC | "_")+ } strict_identifier = @{ strict_identifier_part ~ ("-" ~ strict_identifier_part)* } -// TODO: accept glob characters? // TODO: accept more ASCII meta characters such as "#" and ","? bare_string = @{ ( ASCII_ALPHANUMERIC - | " " | "+" | "-" | "." | "@" | "_" | "/" | "\\" + | " " | "+" | "-" | "." | "@" | "_" | "*" | "?" | "[" | "]" | "/" | "\\" | '\u{80}'..'\u{10ffff}' )+ } diff --git a/lib/src/fileset_parser.rs b/lib/src/fileset_parser.rs index 884c6d687e..4274f7c9fd 100644 --- a/lib/src/fileset_parser.rs +++ b/lib/src/fileset_parser.rs @@ -458,6 +458,10 @@ mod tests { parse_into_kind(r#"Windows\Path"#), Ok(ExpressionKind::Identifier(r#"Windows\Path"#)) ); + assert_eq!( + parse_into_kind("glob*[chars]?"), + Ok(ExpressionKind::Identifier("glob*[chars]?")) + ); } #[test] @@ -502,6 +506,13 @@ mod tests { value: "bar".to_owned() }) ); + assert_eq!( + parse_into_kind(" foo:glob*[chars]? "), + Ok(ExpressionKind::StringPattern { + kind: "foo", + value: "glob*[chars]?".to_owned() + }) + ); assert_eq!( parse_into_kind(r#" foo:"bar" "#), Ok(ExpressionKind::StringPattern { @@ -645,6 +656,13 @@ mod tests { value: " bar baz".to_owned() }) ); + assert_eq!( + parse_maybe_bare_into_kind("foo:glob * [chars]?"), + Ok(ExpressionKind::StringPattern { + kind: "foo", + value: "glob * [chars]?".to_owned() + }) + ); assert_eq!( parse_maybe_bare_into_kind("foo:bar:baz"), Err(FilesetParseErrorKind::SyntaxError)