Skip to content

fix(picker.util): require trailing slash when matching git root in truncpath#2877

Open
madmaxieee wants to merge 1 commit into
folke:mainfrom
madmaxieee:main
Open

fix(picker.util): require trailing slash when matching git root in truncpath#2877
madmaxieee wants to merge 1 commit into
folke:mainfrom
madmaxieee:main

Conversation

@madmaxieee

@madmaxieee madmaxieee commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

Description

When Snacks.git.get_root() returns "." (e.g. when inside a git repo using a relative path), the truncpath function's root-matching logic used path:find(root, 1, true) == 1. This bare match on "." would also match the leading dot of dotfiles like .stylua.toml, causing the root-replacement logic to consume the dot and produce corrupted paths, e.g. .stylua.toml → ./tylua.toml.

The character after the dot was consumed as part of the root match by path:sub(#root + 2).

Changed the match from path:find(root, 1, true) to path:find(root .. "/", 1, true), requiring a trailing / after the root. This ensures the root is only matched as a directory prefix, so dotfiles and other paths starting with . are left intact. The slash after "." is assumed and removed anyways (the +2 part), so it's semantically the same.

…uncpath

When `git.get_root` returns "." (e.g. inside a git repo with a
relative path), the old `path:find(root, 1, true)` would match the
leading dot of dotfiles like ".stylua.toml", replacing it with the
root tail and producing "./tylua.toml".

By matching `root .. "/"` instead of bare `root`, we ensure the
root is only matched as a directory prefix, so dotfiles and other
paths starting with "." are left intact.
@github-actions github-actions Bot added size/xs Extra small PR (<3 lines changed) picker and removed size/xs Extra small PR (<3 lines changed) labels Jun 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant