numtide / treefmt

one CLI to format your repo [maintainers=@zimbatm,@brianmcgee]
https://treefmt.com
MIT License
621 stars 38 forks source link

treefmt treats relative paths as relative to the tree root, rather than the current working directory #443

Closed jfly closed 1 month ago

jfly commented 1 month ago

treefmt refuses to format files relative to $PWD when I'm in a subdirectory of my project.

This works:

./ $ treefmt subdir/tracked.py
traversed 1 files
emitted 1 files for processing
formatted 1 files (0 changed) in 143ms

But if I'm in subdir/:

subdir/ $ treefmt ./tracked.py
Error: path ./tracked.py not found within the tree root /tmp/tmp.NFu4zPpIQ9

But this does work if I use the same relative path from before:

subdir/ $ treefmt subdir/tracked.py
traversed 1 files
emitted 0 files for processing
formatted 0 files (0 changed) in 17ms

To Reproduce

Here's the setup for the above commands:

$ cd "$(mktemp -d)"
$ git init
$ mkdir subdir
$ touch subdir/tracked.py
$ git add --intent-to-add subdir/tracked.py

$ nix shell github:numtide/treefmt nixpkgs#black
$ treefmt --version
treefmt v659aa0f
$ cat treefmt.toml   # create this file
[formatter.python]
command = "black"
includes = ["*.py"]

Expected behavior

I expect treefmt to interpret relative paths relative to the current working directory, not the tree root.

System information

See above. I'm using 659aa0f.

jfly commented 1 month ago

Fix out for review here: https://github.com/numtide/treefmt/pull/445/

brianmcgee commented 1 month ago

Fixed with #445