From 803c6103b8f3264ccbe6cab3588a8954e7f8f44b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Filip=20Kaln=C3=BD?= Date: Mon, 28 Oct 2024 10:37:42 +0100 Subject: [PATCH 1/4] Allow changing directory with lua command --- lua/git-worktree/init.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/git-worktree/init.lua b/lua/git-worktree/init.lua index 0fb5295..3279050 100644 --- a/lua/git-worktree/init.lua +++ b/lua/git-worktree/init.lua @@ -152,7 +152,7 @@ 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) + local cmd = string.format("%s '%s'", M._config.change_directory_command, worktree_path) status:log().debug("Changing to directory " .. worktree_path) vim.cmd(cmd) current_worktree_path = worktree_path From ec7e5904c5584e706fa76c57b4bec2804823cf1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Filip=20Kaln=C3=BD?= Date: Mon, 28 Oct 2024 17:54:12 +0100 Subject: [PATCH 2/4] fix(chdir): typo in error message --- lua/git-worktree/init.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/git-worktree/init.lua b/lua/git-worktree/init.lua index 3279050..d47c366 100644 --- a/lua/git-worktree/init.lua +++ b/lua/git-worktree/init.lua @@ -157,7 +157,7 @@ local function change_dirs(path) vim.cmd(cmd) 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 From cca42039a62356b3e4eb118d250b7740b6e54b4c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Filip=20Kaln=C3=BD?= Date: Mon, 28 Oct 2024 19:30:59 +0100 Subject: [PATCH 3/4] fix(delete): change directory to root if deleting current worktree --- lua/git-worktree/init.lua | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/lua/git-worktree/init.lua b/lua/git-worktree/init.lua index d47c366..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,9 +158,7 @@ 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 change to directory: ' ..worktree_path) @@ -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) From 95698b9662e78032370c70876ca0f91f974de398 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Filip=20Kaln=C3=BD?= Date: Tue, 29 Oct 2024 11:11:16 +0100 Subject: [PATCH 4/4] fix(telescope): apply PP#124 --- lua/telescope/_extensions/git_worktree.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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