Skip to content

treefmt-tree-root config option isn't respected in Jujutsu workspaces #704

@rockboynton

Description

@rockboynton

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:

  1. Have a jujutsu repo with this structure:
repo-root/          ← .jj lives here, no .git
├── other-project/
│   └── shell.nix
└── my-project/
    └── treefmt.toml
  1. my-project/treefmt.toml contains:
tree-root-file = "treefmt.toml"

[formatter.nix]
command = "nixpkgs-fmt"
includes = ["*.nix"]
  1. Run treefmt --no-cache -vv from my-project/.
  2. 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
  1. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions