From 5bdbc95cced22341526cab5e9ee2784dff96b686 Mon Sep 17 00:00:00 2001 From: Phil Stainer Date: Wed, 7 Sep 2022 16:40:50 +0100 Subject: [PATCH 1/2] feat: add base directory config --- README.md | 4 ++++ lua/git-worktree/init.lua | 1 + lua/telescope/_extensions/git_worktree.lua | 6 ++++++ 3 files changed, 11 insertions(+) diff --git a/README.md b/README.md index a1b8ed2..94afd84 100644 --- a/README.md +++ b/README.md @@ -71,6 +71,9 @@ git config remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*" ## Options +`base_directory`: Allow's you to define a base path for the creation of new +worktrees. + `change_directory_command`: The vim command used to change to the new worktree directory. Set this to `tcd` if you want to only change the `pwd` for the current vim Tab. @@ -89,6 +92,7 @@ edit the wrong files. ```lua require("git-worktree").setup({ + base_directory = -- default: "./" change_directory_command = -- default: "cd", update_on_change = -- default: true, update_on_change_command = -- default: "e .", diff --git a/lua/git-worktree/init.lua b/lua/git-worktree/init.lua index 0fb5295..618d182 100644 --- a/lua/git-worktree/init.lua +++ b/lua/git-worktree/init.lua @@ -535,6 +535,7 @@ end M.setup = function(config) config = config or {} M._config = vim.tbl_deep_extend("force", { + base_directory = './', change_directory_command = "cd", update_on_change = true, update_on_change_command = "e .", diff --git a/lua/telescope/_extensions/git_worktree.lua b/lua/telescope/_extensions/git_worktree.lua index 905a358..0ed4a60 100644 --- a/lua/telescope/_extensions/git_worktree.lua +++ b/lua/telescope/_extensions/git_worktree.lua @@ -130,6 +130,12 @@ local create_worktree = function(opts) if name == "" then name = branch end + + if string.match(name, '/') == nil and + git_worktree._config.base_directory then + name = git_worktree._config.base_directory .. branch + end + git_worktree.create_worktree(name, branch) end) end) From 343f51ec38eb4b704727d33d491e26d266b1b18d Mon Sep 17 00:00:00 2001 From: Phil Stainer Date: Sun, 11 Sep 2022 17:19:41 +0100 Subject: [PATCH 2/2] fix: should use name --- lua/telescope/_extensions/git_worktree.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/telescope/_extensions/git_worktree.lua b/lua/telescope/_extensions/git_worktree.lua index 0ed4a60..6155912 100644 --- a/lua/telescope/_extensions/git_worktree.lua +++ b/lua/telescope/_extensions/git_worktree.lua @@ -133,7 +133,7 @@ local create_worktree = function(opts) if string.match(name, '/') == nil and git_worktree._config.base_directory then - name = git_worktree._config.base_directory .. branch + name = git_worktree._config.base_directory .. name end git_worktree.create_worktree(name, branch)