| 1 |
# Filesets |
| 2 |
|
| 3 |
Jujutsu supports a functional language for selecting a set of files. |
| 4 |
Expressions in this language are called "filesets" (the idea comes from |
| 5 |
[Mercurial](https://repo.mercurial-scm.org/hg/help/filesets)). The language |
| 6 |
consists of file patterns, operators, and functions. |
| 7 |
|
| 8 |
## Quoting file names |
| 9 |
|
| 10 |
Many `jj` commands accept fileset expressions as positional arguments. File |
| 11 |
names passed to these commands [must be quoted][string-literals] if they contain |
| 12 |
whitespace or meta characters. However, as a special case, quotes can be omitted |
| 13 |
if the expression has no operators nor function calls. For example: |
| 14 |
|
| 15 |
* `jj diff 'Foo Bar'` (shell quotes are required, but inner quotes are optional) |
| 16 |
* `jj diff '~"Foo Bar"'` (both shell and inner quotes are required) |
| 17 |
* `jj diff '"Foo(1)"'` (both shell and inner quotes are required) |
| 18 |
|
| 19 |
Glob characters aren't considered meta characters, but shell quotes are still |
| 20 |
required: |
| 21 |
|
| 22 |
* `jj diff '~glob:**/*.rs'` |
| 23 |
|
| 24 |
[string-literals]: templates.md#stringliteral-type |
| 25 |
|
| 26 |
## File patterns |
| 27 |
|
| 28 |
The following patterns are supported. In all cases, we do not mention any shell |
| 29 |
quoting that might be necessary, and the quotes around `"path"` are optional if |
| 30 |
the path [has no special characters](#quoting-file-names). |
| 31 |
|
| 32 |
By default, `"path"` is parsed as a `prefix-glob:` pattern, which matches |
| 33 |
cwd-relative path prefix. |
| 34 |
|
| 35 |
* `cwd:"path"`: Matches cwd-relative path prefix (file or files under directory |
| 36 |
recursively.) |
| 37 |
* `file:"path"` or `cwd-file:"path"`: Matches cwd-relative file (or exact) path. |
| 38 |
* `glob:"pattern"` or `cwd-glob:"pattern"`: Matches file paths with cwd-relative |
| 39 |
Unix-style shell [wildcard `pattern`][glob]. For example, `glob:"*.c"` will |
| 40 |
match all `.c` files in the current working directory non-recursively. |
| 41 |
* `prefix-glob:"pattern"` or `cwd-prefix-glob:"pattern"`: Like `glob:`, but also |
| 42 |
matches path prefix (file or files under directory recursively.) For example, |
| 43 |
`prefix-glob:"*.d"` is equivalent to `glob:"*.d" | glob:"*.d/**"`. |
| 44 |
* `root:"path"`: Matches workspace-relative path prefix (file or files under |
| 45 |
directory recursively.) |
| 46 |
* `root-file:"path"`: Matches workspace-relative file (or exact) path. |
| 47 |
* `root-glob:"pattern"`: Matches file paths with workspace-relative Unix-style |
| 48 |
shell [wildcard `pattern`][glob]. |
| 49 |
* `root-prefix-glob:"pattern"`: Like `root-glob:`, but also matches path prefix |
| 50 |
(file or files under directory recursively.) |
| 51 |
|
| 52 |
Glob patterns support case-insensitive matching by appending `-i` to the pattern |
| 53 |
name. For example, `glob-i:"*.TXT"` will match both `file.txt` and `FILE.TXT`. |
| 54 |
|
| 55 |
[glob]: https://docs.rs/globset/latest/globset/#syntax |
| 56 |
|
| 57 |
## Operators |
| 58 |
|
| 59 |
The following operators are supported. `x` and `y` below can be any fileset |
| 60 |
expressions. |
| 61 |
|
| 62 |
Operators are listed in order of binding power from strongest to weakest, e.g. |
| 63 |
`x | y & z` is interpreted as `x | (y & z)` since `&` has stronger binding power |
| 64 |
than `|`. Infix operators of the same binding power are parsed from left to |
| 65 |
right, e.g. `x ~ y & z` is interpreted as `(x ~ y) & z` rather than `x ~ (y & |
| 66 |
z)`. |
| 67 |
|
| 68 |
As seen above, parentheses can be used to control evaluation order, e.g. `(x & |
| 69 |
y) | z` or `x & (y | z)`. |
| 70 |
|
| 71 |
1. * `f(x)`: Function call. |
| 72 |
|
| 73 |
2. * `p:x`: File pattern or pattern alias named `p`. |
| 74 |
|
| 75 |
3. * `~x`: Matches everything but `x`. |
| 76 |
|
| 77 |
4. * `x & y`: Matches both `x` and `y`. |
| 78 |
* `x ~ y`: Matches `x` but not `y`. |
| 79 |
|
| 80 |
5. * `x | y`: Matches either `x` or `y` (or both). |
| 81 |
|
| 82 |
## Functions |
| 83 |
|
| 84 |
You can also specify patterns by using functions. |
| 85 |
|
| 86 |
* `all()`: Matches everything. |
| 87 |
* `none()`: Matches nothing. |
| 88 |
|
| 89 |
## Aliases |
| 90 |
|
| 91 |
New symbols, functions, and `<name>:<value>` patterns can be defined in the |
| 92 |
config file, by using any combination of the predefined symbols / functions and |
| 93 |
other aliases. |
| 94 |
|
| 95 |
Alias functions can be overloaded by the number of parameters. However, builtin |
| 96 |
function will be shadowed by name, and can't co-exist with aliases. |
| 97 |
|
| 98 |
For example: |
| 99 |
|
| 100 |
```toml |
| 101 |
[fileset-aliases] |
| 102 |
LOCK = '**/Cargo.lock | **/package-lock.json | **/uv.lock' |
| 103 |
'not:x' = '~x' |
| 104 |
``` |
| 105 |
|
| 106 |
### Alias descriptions |
| 107 |
|
| 108 |
Alias descriptions can be surfaced in shell completions by defining the alias |
| 109 |
as a table with `.doc` and `.definition` properties. For example: |
| 110 |
|
| 111 |
```toml |
| 112 |
[fileset-aliases] |
| 113 |
LOCK = { |
| 114 |
definition = '**/Cargo.lock | **/package-lock.json | **/uv.lock', |
| 115 |
doc = 'Lockfiles' |
| 116 |
} |
| 117 |
``` |
| 118 |
|
| 119 |
You can also use the dotted key syntax: |
| 120 |
|
| 121 |
```toml |
| 122 |
[fileset-aliases] |
| 123 |
LOCK.definition = '**/Cargo.lock | **/package-lock.json | **/uv.lock' |
| 124 |
LOCK.doc = 'Lockfiles' |
| 125 |
``` |
| 126 |
|
| 127 |
## Examples |
| 128 |
|
| 129 |
Show diff excluding `Cargo.lock`. |
| 130 |
|
| 131 |
```shell |
| 132 |
jj diff '~Cargo.lock' |
| 133 |
``` |
| 134 |
|
| 135 |
List files in `src` excluding Rust sources. |
| 136 |
|
| 137 |
```shell |
| 138 |
jj file list 'src ~ glob:"**/*.rs"' |
| 139 |
``` |
| 140 |
|
| 141 |
Split a revision in two, putting `foo` into the second commit. |
| 142 |
|
| 143 |
```shell |
| 144 |
jj split '~foo' |
| 145 |
``` |