@@ -297,6 +297,38 @@ actions.insert_value = function(prompt_bufnr)
297297 return entry .value
298298end
299299
300+ --- Create and checkout a new git branch if it doesn't already exist
301+ --- @param prompt_bufnr number : The prompt bufnr
302+ actions .git_create_branch = function (prompt_bufnr )
303+ local cwd = action_state .get_current_picker (prompt_bufnr ).cwd
304+ local new_branch = action_state .get_current_line ()
305+
306+ if new_branch == " " then
307+ print (' Please enter the name of the new branch to create' )
308+ else
309+ local confirmation = vim .fn .input (string.format (' Create new branch "%s"? [y/n]: ' , new_branch ))
310+ if string.len (confirmation ) == 0 or string.sub (string.lower (confirmation ), 0 , 1 ) ~= ' y' then
311+ print (string.format (' Didn\' t create branch "%s"' , new_branch ))
312+ return
313+ end
314+
315+ actions .close (prompt_bufnr )
316+
317+ local _ , ret , stderr = utils .get_os_command_output ({ ' git' , ' checkout' , ' -b' , new_branch }, cwd )
318+ if ret == 0 then
319+ print (string.format (' Switched to a new branch: %s' , new_branch ))
320+ else
321+ print (string.format (
322+ ' Error when creating new branch: %s Git returned "%s"' ,
323+ new_branch ,
324+ table.concat (stderr , ' ' )
325+ ))
326+ end
327+ end
328+ end
329+
330+ --- Checkout an existing git branch
331+ --- @param prompt_bufnr number : The prompt bufnr
300332actions .git_checkout = function (prompt_bufnr )
301333 local cwd = action_state .get_current_picker (prompt_bufnr ).cwd
302334 local selection = action_state .get_selected_entry ()
@@ -313,6 +345,8 @@ actions.git_checkout = function(prompt_bufnr)
313345 end
314346end
315347
348+ --- Tell git to track the currently selected remote branch in Telescope
349+ --- @param prompt_bufnr number : The prompt bufnr
316350actions .git_track_branch = function (prompt_bufnr )
317351 local cwd = action_state .get_current_picker (prompt_bufnr ).cwd
318352 local selection = action_state .get_selected_entry ()
@@ -329,6 +363,8 @@ actions.git_track_branch = function(prompt_bufnr)
329363 end
330364end
331365
366+ --- Delete the currently selected branch
367+ --- @param prompt_bufnr number : The prompt bufnr
332368actions .git_delete_branch = function (prompt_bufnr )
333369 local cwd = action_state .get_current_picker (prompt_bufnr ).cwd
334370 local selection = action_state .get_selected_entry ()
@@ -349,6 +385,8 @@ actions.git_delete_branch = function(prompt_bufnr)
349385 end
350386end
351387
388+ --- Rebase to selected git branch
389+ --- @param prompt_bufnr number : The prompt bufnr
352390actions .git_rebase_branch = function (prompt_bufnr )
353391 local cwd = action_state .get_current_picker (prompt_bufnr ).cwd
354392 local selection = action_state .get_selected_entry ()
@@ -369,6 +407,8 @@ actions.git_rebase_branch = function(prompt_bufnr)
369407 end
370408end
371409
410+ --- Stage/unstage selected file
411+ --- @param prompt_bufnr number : The prompt bufnr
372412actions .git_staging_toggle = function (prompt_bufnr )
373413 local cwd = action_state .get_current_picker (prompt_bufnr ).cwd
374414 local selection = action_state .get_selected_entry ()
0 commit comments