Describe the bug
When tree-root-file is configured in treefmt.toml, the jujutsu walker does not filter its file listing to the resolved tree root. It enumerates all tracked files from the jj repo root, then passes ../-prefixed relative paths to formatter glob matchers. This causes formatters to match and process files outside the intended tree root.
The git walker correctly scopes file enumeration to the tree root directory. The jujutsu walker should behave the same way.
This is only a problem in non-colocated jj repos, and jj worktrees, which also don't have a .git
To Reproduce
Steps to reproduce the behavior:
- Have a jujutsu repo with this structure:
repo-root/ ← .jj lives here, no .git
├── other-project/
│ └── shell.nix
└── my-project/
└── treefmt.toml
- my-project/treefmt.toml contains:
tree-root-file = "treefmt.toml"
[formatter.nix]
command = "nixpkgs-fmt"
includes = ["*.nix"]
- Run
treefmt --no-cache -vv from my-project/.
- Observe that the jujutsu walker processes files from other-project/ and the entire repo:
INFO config: tree root: /path/to/repo-root/my-project
DEBU walk | jujutsu: processing file: /path/to/repo-root/other-project/shell.nix
DEBU formatter | nix: match: /path/to/repo-root/other-project/shell.nix
- By contrast, if the repo is colocated (has a .git directory), treefmt selects the git walker and correctly processes only files within my-project/.
Expected behavior
The jujutsu walker should filter its file listing to only include files within the resolved tree root, matching the behavior of the git walker. Files outside the tree root should not be walked, matched, or formatted.
System information
- treefmt v2.4.0
- jj 0.40 (non-colocated workspaces, i.e. jj-only with no .git directory)
- macOS Darwin 25.5.0˚
Additional context
This particularly affects jujutsu worktrees created from a colocated repo. The main worktree has both .jj and .git, so treefmt picks the git walker (which works correctly). Additional jj worktrees only have .jj, triggering the jujutsu walker and the broken behavior.
Workaround: set TREEFMT_WALK=filesystem and use TREEFMT_TREE_ROOT env var (after removing tree-root-file from the config to avoid the "at most one of tree-root, tree-root-cmd or tree-root-file" conflict). This requires adding explicit excludes for directories like target/ that gitignore would normally handle.
Describe the bug
When
tree-root-fileis configured intreefmt.toml, the jujutsu walker does not filter its file listing to the resolved tree root. It enumerates all tracked files from the jj repo root, then passes ../-prefixed relative paths to formatter glob matchers. This causes formatters to match and process files outside the intended tree root.The git walker correctly scopes file enumeration to the tree root directory. The jujutsu walker should behave the same way.
This is only a problem in non-colocated jj repos, and jj worktrees, which also don't have a
.gitTo Reproduce
Steps to reproduce the behavior:
repo-root/ ← .jj lives here, no .git ├── other-project/ │ └── shell.nix └── my-project/ └── treefmt.tomltreefmt --no-cache -vvfrommy-project/.Expected behavior
The jujutsu walker should filter its file listing to only include files within the resolved tree root, matching the behavior of the git walker. Files outside the tree root should not be walked, matched, or formatted.
System information
Additional context
This particularly affects jujutsu worktrees created from a colocated repo. The main worktree has both .jj and .git, so treefmt picks the git walker (which works correctly). Additional jj worktrees only have .jj, triggering the jujutsu walker and the broken behavior.
Workaround: set TREEFMT_WALK=filesystem and use TREEFMT_TREE_ROOT env var (after removing tree-root-file from the config to avoid the "at most one of tree-root, tree-root-cmd or tree-root-file" conflict). This requires adding explicit excludes for directories like target/ that gitignore would normally handle.