Skip to content

Commit fe43ffc

Browse files
authored
Update git_worktree.lua
apply PR ThePrimeagen#106 ## why - main repo owner hasn't applied PR - fixes telescope error when switching git worktree
1 parent d7f4e25 commit fe43ffc

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

lua/telescope/_extensions/git_worktree.lua

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,9 +163,19 @@ local telescope_git_worktree = function(opts)
163163
local index = #results + 1
164164
for key, val in pairs(widths) do
165165
if key == 'path' then
166-
local new_path = utils.transform_path(opts, entry[key])
167-
local path_len = strings.strdisplaywidth(new_path or "")
168-
widths[key] = math.max(val, path_len)
166+
-- Some users have found that transform_path raises an error because telescope.state#get_status
167+
-- outputs an empty table. When that happens, we need to use the default value.
168+
-- This seems to happen in distros such as AstroNvim and NvChad
169+
--
170+
-- Reference: https://github.com/ThePrimeagen/git-worktree.nvim/issues/97
171+
local transformed_ok, new_path = pcall(utils.transform_path, opts, entry[key])
172+
173+
if transformed_ok then
174+
local path_len = strings.strdisplaywidth(new_path or "")
175+
widths[key] = math.max(val, path_len)
176+
else
177+
widths[key] = math.max(val, strings.strdisplaywidth(entry[key] or ""))
178+
end
169179
else
170180
widths[key] = math.max(val, strings.strdisplaywidth(entry[key] or ""))
171181
end

0 commit comments

Comments
 (0)