Skip to content

Commit 2517409

Browse files
committed
Handle creating worktree from origin branch
## what - apply PR ThePrimeagen#104 ## how ## why - main repo owner hasn't applied PR - fixes issue when creating worktree from a origin branch ## where - ./lua/git-worktree/init.lua ## usage
1 parent 9f39620 commit 2517409

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

lua/git-worktree/init.lua

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,9 +174,15 @@ local function create_worktree_job(path, branch, found_branch)
174174
local worktree_add_args = {'worktree', 'add'}
175175

176176
if not found_branch then
177-
table.insert(worktree_add_args, '-b')
178-
table.insert(worktree_add_args, branch)
179-
table.insert(worktree_add_args, path)
177+
if branch:find('^origin/') then
178+
table.insert(worktree_add_args, path)
179+
local local_branch_name = branch:gsub("origin/", "")
180+
table.insert(worktree_add_args, local_branch_name)
181+
else
182+
table.insert(worktree_add_args, '-b')
183+
table.insert(worktree_add_args, branch)
184+
table.insert(worktree_add_args, path)
185+
end
180186
else
181187
table.insert(worktree_add_args, path)
182188
table.insert(worktree_add_args, branch)

0 commit comments

Comments
 (0)