@@ -9,6 +9,7 @@ local conf = require('telescope.config').values
99local git_worktree = require (' git-worktree' )
1010local Config = require (' git-worktree.config' )
1111local Git = require (' git-worktree.git' )
12+ local Log = require (' git-worktree.logger' )
1213
1314local force_next_deletion = false
1415
9192local delete_success_handler = function (opts )
9293 opts = opts or {}
9394 force_next_deletion = false
94- if confirm_branch_deletion () and opts .branch ~= nil then
95+ if opts . branch ~= nil and opts .branch ~= ' HEAD ' and confirm_branch_deletion () then
9596 local delete_branch_job = Git .delete_branch_job (opts .branch )
9697 if delete_branch_job ~= nil then
98+ delete_branch_job :after_success (vim .schedule_wrap (function ()
99+ print (' Branch deleted' )
100+ end ))
97101 delete_branch_job :start ()
98102 end
99103 end
@@ -134,6 +138,15 @@ local create_input_prompt = function(opts, cb)
134138 opts .pattern = nil -- show all branches that can be tracked
135139
136140 local path = vim .fn .input (' Path to subtree > ' , opts .branch )
141+ if path == ' ' then
142+ Log .error (" No worktree path provided" )
143+ return
144+ end
145+
146+ if opts .branch == ' ' then
147+ cb (path , nil )
148+ return
149+ end
137150
138151 local branches = vim .fn .systemlist (' git branch --all' )
139152 if # branches == 0 then
@@ -173,17 +186,11 @@ local telescope_create_worktree = function(opts)
173186 git_worktree .switch_worktree (nil )
174187 opts = opts or {}
175188
176- -- TODO: Enable detached HEAD worktree creation, but for this the telescope
177- -- picker git_branches must show refs/tags.
178-
179189 local create_branch = function (prompt_bufnr , _ )
180190 -- if current_line is still not enough to filter everything but user
181191 -- still wants to use it as the new branch name, without selecting anything
182192 local branch = action_state .get_current_line ()
183193 actions .close (prompt_bufnr )
184- if branch == nil then
185- return
186- end
187194 opts .branch = branch
188195 create_input_prompt (opts , function (path , upstream )
189196 git_worktree .create_worktree (path , branch , upstream )
@@ -197,7 +204,8 @@ local telescope_create_worktree = function(opts)
197204 -- selected_entry can be null if current_line filters everything
198205 -- and there's no branch shown
199206 local branch = selected_entry ~= nil and selected_entry .value or current_line
200- if branch == nil then
207+ if branch == nil or branch == ' ' then
208+ Log .error (" No branch selected" )
201209 return
202210 end
203211 opts .branch = branch
0 commit comments