numtide / treefmt

one CLI to format your repo
https://treefmt.com
MIT License
551 stars 33 forks source link

treefmt(1) does not work with files added by "git add -f" #182

Open KAction opened 1 year ago

KAction commented 1 year ago

I keep all my configuration stuff, ad-hoc scripts and so on in git repository that is cloned into my home directory. This workflow is described in greater detail in following blog article: https://drewdevault.com/2019/12/30/dotfiles.html

As configured by ".gitignore" in home directory, everything is ignored, and when I want to start tracking particular script or configuration file, I "git add -f" it. And once I started tracking file, I also want to auto-format it.

Problem is that treefmt(1) reads my .gitignore and concludes that it should not traverse anywhere, so it finds no files to format and does nothing. This behaviour makes perfect sense (disregarding .gitignore and traversing whole ~/ would take ages), yet it does not work for my scenario.

I think reasonable solution that would be mostly backward-compatible would be to additionally process files printed by "git ls-files", so files already tracked in git will always be considered by treefmt(1).

Alternatively, I can manually do "git ls-files .config | xargs treefmt", but that is quite a lot of typing.

zimbatm commented 1 year ago

Thanks, I think it's worth making the file listing a new interface.

The default would be:

[general]
file_listing = "builtin"

It could also support git as a data source:

[general]
file_listing = "git"

Or an arbitrary command to make it generic:

[general]
file_listing = "command"
file_listing_command = ["git", "ls-files"]

This also needs to be overridable from the CLI. treefmt --option general.file_listing=git.

I don't plan on implementing this right now, but that's how I would like it to look.