Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions lua/git-worktree/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -145,19 +145,23 @@ 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)

local previous_worktree = current_worktree_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
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion lua/telescope/_extensions/git_worktree.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down