@@ -302,13 +302,16 @@ local function create_worktree(path, branch, upstream, found_branch)
302302 worktree_path = Path :new (git_worktree_root , path ):absolute ()
303303 end
304304
305- local fetch = Job :new ({
306- ' git' , ' fetch' , ' --all' ,
307- cwd = worktree_path ,
308- on_start = function ()
309- status :next_status (" git fetch --all (This may take a moment)" )
310- end
311- })
305+ local fetch
306+ if M ._config .fetch_on_create then
307+ fetch = Job :new ({
308+ ' git' , ' fetch' , ' --all' ,
309+ cwd = worktree_path ,
310+ on_start = function ()
311+ status :next_status (" git fetch --all (This may take a moment)" )
312+ end
313+ })
314+ end
312315
313316 local set_branch_cmd = ' git'
314317 local set_branch_args = {' branch' , string.format (' --set-upstream-to=%s/%s' , upstream , branch )}
@@ -343,8 +346,12 @@ local function create_worktree(path, branch, upstream, found_branch)
343346 })
344347
345348 if upstream ~= nil then
346- create :and_then_on_success (fetch )
347- fetch :and_then_on_success (set_branch )
349+ if M ._config .fetch_on_create then
350+ create :and_then_on_success (fetch )
351+ fetch :and_then_on_success (set_branch )
352+ else
353+ create :and_then_on_success (set_branch )
354+ end
348355
349356 if M ._config .autopush then
350357 -- These are "optional" operations.
@@ -357,7 +364,9 @@ local function create_worktree(path, branch, upstream, found_branch)
357364 end
358365
359366 create :after_failure (failure (" create_worktree" , create .args , git_worktree_root ))
360- fetch :after_failure (failure (" create_worktree" , fetch .args , worktree_path ))
367+ if M ._config .fetch_on_create then
368+ fetch :after_failure (failure (" create_worktree" , fetch .args , worktree_path ))
369+ end
361370
362371 set_branch :after_failure (failure (" create_worktree" , set_branch .args , worktree_path , true ))
363372
@@ -543,6 +552,7 @@ M.setup = function(config)
543552 confirm_telescope_deletions = false ,
544553 -- should this default to true or false?
545554 autopush = false ,
555+ fetch_on_create = true ,
546556 }, config )
547557end
548558
0 commit comments