From 23eea1c322b65bf863a79bb3cf1dd08b21916aef Mon Sep 17 00:00:00 2001 From: awerebea Date: Wed, 8 May 2024 11:28:14 +0400 Subject: [PATCH] Avoid editing an empty buffer on startup Currently, switching to the worktree after opening Nvim without any path arguments (without an open file in the current window) results in an unnamed buffer being created with the path to the current directory ("." is a directory). With this change, the command to update a currently open file from a path in a switched worktree is executed only if the buffer in the current window has a name (saved as a file). --- 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..d562dde 100644 --- a/lua/git-worktree/init.lua +++ b/lua/git-worktree/init.lua @@ -537,7 +537,7 @@ M.setup = function(config) M._config = vim.tbl_deep_extend("force", { change_directory_command = "cd", update_on_change = true, - update_on_change_command = "e .", + update_on_change_command = "if expand('%:t') != '' | e . | endif", clearjumps_on_change = true, -- default to false to avoid breaking the previous default behavior confirm_telescope_deletions = false,