Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
KAction opened this issue Oct 2, 2022 · 2 comments
Open

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

KAction opened this issue Oct 2, 2022 · 2 comments
Labels
enhancement New feature or request

Comments

@KAction
Copy link

KAction commented Oct 2, 2022

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.

@KAction KAction added the enhancement New feature or request label Oct 2, 2022
@zimbatm
Copy link
Member

zimbatm commented Oct 4, 2022

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.

@brianmcgee
Copy link
Member

This should now work with v2 as we are git aware and traverse staged files when using the default git walker.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants