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

cli: search for the tree root by default #309

Merged
merged 7 commits into from
May 30, 2024
Merged

cli: search for the tree root by default #309

merged 7 commits into from
May 30, 2024

Conversation

zimbatm
Copy link
Member

@zimbatm zimbatm commented May 30, 2024

Restore the treefmt 1.x behaviour where it would search for the tree root by recursively searching for the treefmt.toml file up the filesystem, starting from the current directory.

The --tree-root-file option will be useful to remove this bash wrapper: https://github.com/numtide/treefmt-nix/blob/2fba33a182602b9d49f0b2440513e5ee091d838b/module-options.nix#L116-L135

Fixes #308

Restore the treefmt 1.x behaviour where it would search for the tree
root by recursively searching for the treefmt.toml file up the
filesystem, starting from the current directory.

The `--tree-root-file` option will be useful to remove this bash wrapper: https://github.com/numtide/treefmt-nix/blob/2fba33a182602b9d49f0b2440513e5ee091d838b/module-options.nix#L116-L135

Fixes #308
cli/cli.go Outdated Show resolved Hide resolved
cli/cli.go Outdated Show resolved Hide resolved
cli/format.go Outdated Show resolved Hide resolved
for _, dir := range eachDir(searchDir) {
path := filepath.Join(dir, fileName)
if fileExists(path) {
return path, dir, nil
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how does this handle symlinks? Would it follow a directory symlink that might "escape" into a completely different directory tree?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

eachDir is only decomposing the /path/ string, removing one component after the other. I don't like to follow symlinks because it can lead to infinite loops and other weirdnesses.

fileExists will return true if the file is readable. It can be a symlink to another file, that's fine.

zimbatm and others added 5 commits May 30, 2024 19:10
Co-authored-by: Brian McGee <brian@bmcgee.ie>
kong resolves path types to absolute paths
@zimbatm zimbatm requested a review from brianmcgee May 30, 2024 17:57
@brianmcgee
Copy link
Member

@mergify queue

Copy link
Contributor

mergify bot commented May 30, 2024

queue

✅ The pull request has been merged automatically

The pull request has been merged automatically at 2454542

@mergify mergify bot merged commit 2454542 into main May 30, 2024
5 checks passed
@mergify mergify bot deleted the find-tree-root branch May 30, 2024 18:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

treefmt2 doesn't search for the project root anymore
2 participants