feat: support .gitignore files #19
No reviewers
Labels
No Label
Kind/Breaking
Kind/Bug
Kind/Documentation
Kind/Enhancement
Kind/Feature
Kind/Security
Kind/Testing
Priority
Critical
Priority
High
Priority
Low
Priority
Medium
Reviewed
Confirmed
Reviewed
Duplicate
Reviewed
Invalid
Reviewed
Won't Fix
Status
Abandoned
Status
Blocked
Status
Need More Info
No Milestone
No project
No Assignees
2 Participants
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: numtide/treefmt#19
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "feat/support-gigignore"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Introduces a
--walk
flag which can be used to telltreefmt
how to traverse the directory specified by--tree-root
.By default, it will attempt to use
git ls-files
. If this fails, it falls back to using the filesystem.You can explicitly traverse the filesystem instead of using git by providing
--walk filesystem
.Close #1
@zimbatm ping
The rust ignore crate is a bit weird; it also loads
.ignore
files and generally doesn't traverse any files starting with a.
. That has caused a few issues already. Eg: the latest: https://github.com/numtide/treefmt-nix/pull/146Side point: there might be an argument that inside of a git repo, we could use
git ls-files
as the source of listing. This would be much faster than traversing the filesystem.@ -14,6 +14,7 @@ type Options struct {
ConfigFile string `type:"existingfile" default:"./treefmt.toml"`
FailOnChange bool `help:"Exit with error if any changes were made. Useful for CI"`
Formatters []string `help:"Specify formatters to apply. Defaults to all formatters"`
NoGitignore bool `help:"Ignore .gitignore files within the tree root" default:"false"`
The phrasing is a bit ambiguous. Maybe "Don't respect .gitignore files"?
That's a fair point.
Yeah, I'm currently processing everything and I'd like to keep it like that. Ignoring dot files was brought up on discourse as well.
I think I prefer this rather than polluting things with git related code and logic. Keeps things cleaner
@zimbatm if using
git ls-files
would you make that behaviour opt-in or opt-out?If it's following
git ls-files
then I would not process the .gitignore files. If the user wants to ignore something, they can still ignore them by adding them to the global excludes list.acd4997459
todea0166e2b
dea0166e2b
to9051aa6d0f
@zimbatm I changed the approach, using
git ls-files
instead. I've updated the description and force-pushed.Yeah that's great, I think it's going to make the project so much nicer
@ -0,0 +80,4 @@
}
return eg.Wait()
}
I think a more idiomatic way would be to have an "internal/walker" package.
There you could have a
walker.Walker
interface, and host the FileSystemWalker and GitWalker implementations.And
walker.Detect(path string) (Walker, error)
could detect and return a walker instance based on the path.And a
walker.New(type string, path string) (Walker, error)
in the case where the walker type is named.Made some relevant changes in
bcc4902ed8
@ -17,2 +16,3 @@
Formatters []string `help:"Specify formatters to apply. Defaults to all formatters."`
TreeRoot string `type:"existingdir" default:"."`
Verbosity int `name:"verbose" short:"v" type:"counter" default:"0" env:"LOG_LEVEL" help:"Set the verbosity of logs e.g. -vv"`
Walk string `enum:"filesystem,git" default:"git" help:"The method used to traverse the files within --tree-root. Currently supports 'git' or 'filesystem'."`
The default could be added to the config file, or detected.
Made some relevant changes in
bcc4902ed8
LGTM
@ -0,0 +23,4 @@
func (g *git) Walk(ctx context.Context, fn filepath.WalkFunc) error {
r, w := io.Pipe()
cmd := exec.Command("git", "-C", g.root, "ls-files")
You didn't want to use the go-git package for this?
I tried with
go-git
but couldn't find an efficient way or traversing the worktree. It worked fine on a small repo, but on nixpkgs it broke down badly. Will revisit this again in the future.