diff --git a/lua/git-worktree/init.lua b/lua/git-worktree/init.lua index 0fb5295..7d2ed69 100644 --- a/lua/git-worktree/init.lua +++ b/lua/git-worktree/init.lua @@ -145,6 +145,12 @@ local function emit_on_change(op, metadata) end end +local function change_dirs_internal(path) + local cmd = string.format("%s '%s'", M._config.change_directory_command, path) + status:log().debug("Changing to directory " .. path) + vim.cmd(cmd) +end + local function change_dirs(path) local worktree_path = M.get_worktree_path(path) @@ -152,12 +158,10 @@ local function change_dirs(path) -- vim.loop.chdir(worktree_path) if Path:new(worktree_path):exists() then - local cmd = string.format("%s %s", M._config.change_directory_command, worktree_path) - status:log().debug("Changing to directory " .. worktree_path) - vim.cmd(cmd) + change_dirs_internal(worktree_path) current_worktree_path = worktree_path else - status:error('Could not chang to directory: ' ..worktree_path) + status:error('Could not change to directory: ' ..worktree_path) end if M._config.clearjumps_on_change then @@ -450,6 +454,11 @@ M.delete_worktree = function(path, force, opts) if opts.on_success then opts.on_success() end + if vim.fn.getcwd() == path then + status:next_status("you deleted the current worktree, you will be switched to repo root") + change_dirs_internal(git_worktree_root) + current_worktree_path = nil + end end)) delete:after_failure(function(e) diff --git a/lua/telescope/_extensions/git_worktree.lua b/lua/telescope/_extensions/git_worktree.lua index 706cd2b..8619cb2 100644 --- a/lua/telescope/_extensions/git_worktree.lua +++ b/lua/telescope/_extensions/git_worktree.lua @@ -193,9 +193,10 @@ local telescope_git_worktree = function(opts) } local make_display = function(entry) + local path, _ = utils.transform_path(opts, entry.path) return displayer { { entry.branch, "TelescopeResultsIdentifier" }, - { utils.transform_path(opts, entry.path) }, + { path }, { entry.sha }, } end