numtide / treefmt

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

File change is not detected properly #118

Closed zimbatm closed 3 years ago

zimbatm commented 3 years ago

Describe the bug

I'm not sure exactly of the details but I have observed this myself. Whenever files are getting re-formatted, the tool doesn't show them as such.

This is especially an issue on CI where treefmt --fail-on-change is being used.

To Reproduce

$ echo "  echo foo" > foo.sh
$ cat foo.sh 
  echo foo
$ cargo run
    Finished dev [unoptimized + debuginfo] target(s) in 0.03s
     Running `target/debug/treefmt`
[INFO]: #shell: 1 files processed in 99.95ms

traversed 74 files
matched 51 files to formatters
left with 1 files after cache
of whom 0 files were re-formatted
all of this in 243.84ms

$ cat foo.sh 
echo foo

Expected behavior

It should output of whom 1 files were re-formatted.

System information

NixOS, btrfs filesystem.

More context

Maybe we should listen to https://apenwarr.ca/log/20181113

zimbatm commented 3 years ago

Workaround:

treefmt
# Check if any files have changed
if [[ -n "$(git status --porcelain -unormal)" ]]; then
  echo "-----------------------------"
  echo "ERROR: The project is dirty!"
  echo "-----------------------------"
  git status -unormal
  exit 1
else
  echo "--------------"
  echo "OK: All good!"
  echo "--------------"
fi