numtide / treefmt

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

treefmt refuses to format files when invoked with their absolute paths #442

Closed jfly closed 1 month ago

jfly commented 1 month ago

Tracked relative paths get formatted:

$ treefmt tracked.py
traversed 1 files
emitted 1 files for processing
formatted 1 files (1 changed) in 107ms

Untracked relative path get formatted (thanks @brianmcgee! this works now because of https://github.com/numtide/treefmt/pull/438):

$ treefmt untracked.py
traversed 1 files
emitted 1 files for processing
formatted 1 files (0 changed) in 119ms

Tracked absolute paths get skipped:

$ treefmt $(realpath tracked.py)
Error: path /home/jeremy/tmp/2024-10-12-pyhack-1/tracked.py not found within the tree root /home/jeremy/tmp/2024-10-12-pyhack-1

Untracked absolute paths get skipped:

$ treefmt $(realpath untracked.py)
Error: path /home/jeremy/tmp/2024-10-12-pyhack-1/untracked.py not found within the tree root /home/jeremy/tmp/2024-10-12-pyhack-1

To Reproduce

Here's the setup for the above commands:

$ cd "$(mktemp -d)"
$ git init
$ touch tracked.py
$ touch untracked.py
$ git add --intent-to-add 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'd expect treefmt to format these files.

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