git-worktree.nvim icon indicating copy to clipboard operation
git-worktree.nvim copied to clipboard

Getting error with telescope git_worktrees()

Open globule655 opened this issue 1 year ago • 12 comments

Hi there ! When using the command lua require('telescope').extensions.git_worktree.git_worktrees() I get the following error :

E5108: Error executing lua ...l/share/nvim/lazy/telescope.nvim/lua/telescope/utils.lua:206: attempt to index field 'layout' (a nil value) stack traceback: ...l/share/nvim/lazy/telescope.nvim/lua/telescope/utils.lua:206: in function 'calc_result_length' ...l/share/nvim/lazy/telescope.nvim/lua/telescope/utils.lua:265: in function 'transform_path' ...worktree.nvim/lua/telescope/_extensions/git_worktree.lua:166: in function 'parse_line' ...worktree.nvim/lua/telescope/_extensions/git_worktree.lua:179: in function 'git_worktrees' [string ":lua"]:1: in main chunk

The command lua require('telescope').extensions.git_worktree.create_git_worktree() works just fine.

Tried on windows wsl (ubuntu 22.04), neovim v0.9.2 Release.

Here is my config (kept it barebones). Lazy plugins config:

{ "ThePrimeagen/git-worktree.nvim", config = function() require("telescope").load_extension("git_worktree") end, },

init.lua for mappings (give the same result as executing lua function in command mode) :

`vim.keymap.set("n", "gw", function () require('telescope').extensions.git_worktree.git_worktrees() end, { desc = "Telescope switch & delete worktrees"})

vim.keymap.set("n", "gc", function () require('telescope').extensions.git_worktree.create_git_worktree() end, { desc = "Telescope create worktree"}) `

Thank you very much for the help

EDIT:

I made the test under my home Linux laptop (Fedora 38) and the same thing happens. Aslo tested under plain windows and there the Telescope window does open correctly. However, there is an error every time I try to switch to a worktree saying the directory doesn't exist.

When trying to create a worktree under windows via the telescope extension, the path looks like c:\users\globule\Documents\myawesomegitrepo\c:\users\globule\Documents\myawesomegitrepo\mybranch which leads to an error but it still creates the folder. However, when trying to switch between workspaces created via the telescope extension, I get the error "The workspace doesn't exist, please create it first c:\users\globule\Documents\myawesomegitrepo"

globule655 avatar Oct 27 '23 22:10 globule655

You can make your own fork of the repo and apply a quick fix that @aaronhallaert found. In the file lua/telescope/_extensions/git_worktree.lua comment out line 165 to 171, but leave out line 170

                -- if key == 'path' then
                --     local new_path = utils.transform_path(opts, entry[key])
                --     local path_len = strings.strdisplaywidth(new_path or "")
                --     widths[key] = math.max(val, path_len)
                -- else
                    widths[key] = math.max(val, strings.strdisplaywidth(entry[key] or ""))
                -- end

And then use your own fork in vim until this repo gets a PR.

SimonNyvall avatar Nov 05 '23 10:11 SimonNyvall

I ran into the same issue, the fork from @nooproblem fixed it for me. :pray:

  • https://github.com/nooproblem/git-worktree.nvim

Are there any attempts to add this fix to this repo as well?

mschreil avatar Dec 01 '23 11:12 mschreil

Late reply from me but thank you very much for your help.

I found a quick fix by removing path_display = { "truncate" }, in the telescope configuration and didn't think about this anymore after that. I will try @SimonNyvall's fix though 👍 Thanks again !

globule655 avatar Dec 01 '23 12:12 globule655

I am now maintaining the repo, I think it is fixed on my fork. I am working on a v2 to improve this plugin.

https://github.com/polarmutex/git-worktree.nvim

polarmutex avatar Dec 02 '23 01:12 polarmutex

Just tested it with your fork @polarmutex Unfortunately, got the same issue again when calling require('telescope').extensions.git_worktree.git_worktrees()

E5108: Error executing lua: ...l/share/nvim/lazy/telescope.nvim/lua/telescope/utils.lua:206: attempt to index field 'layout' (a nil value)                                                  
stack traceback:                                                                                                                                                                            
        ...l/share/nvim/lazy/telescope.nvim/lua/telescope/utils.lua:206: in function 'calc_result_length'                                                                                   
        ...l/share/nvim/lazy/telescope.nvim/lua/telescope/utils.lua:265: in function 'transform_path'                                                                                       
        ...worktree.nvim/lua/telescope/_extensions/git_worktree.lua:166: in function 'parse_line'                                                                                           
        ...worktree.nvim/lua/telescope/_extensions/git_worktree.lua:179: in function 'git_worktrees'                                                                                        
        /home/msc/.config/nvim/lua/custom/mappings.lua:54: in function </home/msc/.config/nvim/lua/custom/mappings.lua:53> 

Also checked my telescope settings and I have path_display = { "truncate" }, . Is it required to remove this, as @globule655 suggested?

mschreil avatar Dec 04 '23 08:12 mschreil

I will look into it today

polarmutex avatar Dec 04 '23 11:12 polarmutex

with that option, I do see errors (I can look into this later). removing that option I see the telescope window pop up

polarmutex avatar Dec 04 '23 13:12 polarmutex

I would really like to keep path_display = { "truncate" }. Can somebody please fix this?

paulkre avatar Jan 14 '24 14:01 paulkre

Can confirm, removing path_display = { "truncate" } fixed the issue

qustavo avatar Mar 21 '24 14:03 qustavo

I would really like to keep path_display = { "truncate" }.

You can customize path_display configuration when calling a specific extension like git_worktree.git_worktrees().

I have the following mapping which overrides my default path_display = { "truncate" }:

{
  "<leader>gws",
  function()
    require("telescope").extensions.git_worktree.git_worktrees({
      path_display = {},
    })
  end,
  desc = "Manage Worktrees",
},

epilande avatar Apr 04 '24 20:04 epilande

Hi all, It's broken again after a recent update to the telescope repository (the specific commit that introduced the incompatibility is 10d57f38f538cd6c22330a2a4b74efe132ff35b5, discovered it by git bisect)

Telescope message:

[telescope] [WARN  11:13:17] /home/user/.local/share/nvim/lazy/telescope.nvim/lua/telescope/pickers.lua:669: Finder failed with msg:  ...lazy/telescope.nvim/lua/telescope/pickers/highlights.lua:33: Invalid 'hl_group': Expected Lua string

awerebea avatar Apr 24 '24 07:04 awerebea

The PR that fixes this has been created.

awerebea avatar Apr 29 '24 20:04 awerebea