@@ -9,6 +9,7 @@ local in_bare_repo_from_origin_1_worktree = harness.in_bare_repo_from_origin_1_w
99local in_repo_from_origin_1_worktree = harness .in_repo_from_origin_1_worktree
1010local in_repo_from_local_no_worktrees = harness .in_repo_from_local_no_worktrees
1111local in_bare_repo_from_origin_2_worktrees = harness .in_bare_repo_from_origin_2_worktrees
12+ local in_bare_repo_from_origin_3_worktrees = harness .in_bare_repo_from_origin_3_worktrees
1213local in_repo_from_origin_2_worktrees = harness .in_repo_from_origin_2_worktrees
1314local check_git_worktree_exists = harness .check_git_worktree_exists
1415local check_branch_upstream = harness .check_branch_upstream
@@ -484,6 +485,53 @@ describe('git-worktree', function()
484485 assert .True (featC_abs_A_path == get_current_file ())
485486 end ))
486487
488+ it (' in a featB worktree(bare) with file A inside featC open, switch to featD and switch to file A in other worktree' ,
489+ in_bare_repo_from_origin_3_worktrees (function ()
490+
491+ local featB_path = " featB"
492+ local featB_abs_path = git_worktree :get_root () .. Path .path .sep .. featB_path
493+ local featB_abs_A_path = featB_abs_path .. Path .path .sep .. " A.txt"
494+
495+ local featC_path = " featC"
496+ local featC_abs_path = git_worktree :get_root () .. Path .path .sep .. featC_path
497+ local featC_abs_A_path = featC_abs_path .. Path .path .sep .. " A.txt"
498+
499+ local featD_path = " featD"
500+ local featD_abs_path = git_worktree :get_root () .. Path .path .sep .. featD_path
501+ local featD_abs_A_path = featD_abs_path .. Path .path .sep .. " A.txt"
502+
503+ -- switch to featB worktree
504+ git_worktree .switch_worktree (featB_path )
505+
506+ vim .fn .wait (
507+ 10000 ,
508+ function ()
509+ return completed_switch
510+ end ,
511+ 1000
512+ )
513+
514+ -- open A file
515+ vim .cmd (" e ../featC/A.txt" )
516+ -- make sure it is opened
517+ assert .True (featC_abs_A_path == get_current_file ())
518+
519+ -- switch to featD worktree
520+ reset_variables ()
521+ git_worktree .switch_worktree (featD_path )
522+
523+ vim .fn .wait (
524+ 10000 ,
525+ function ()
526+ return completed_switch
527+ end ,
528+ 1000
529+ )
530+
531+ -- make sure it switch to file in other tree
532+ assert .True (featD_abs_A_path == get_current_file ())
533+ end ))
534+
487535 it (' in a featB worktree(non bare) with file A open, switch to featC and switch to file A in other worktree' ,
488536 in_repo_from_origin_2_worktrees (function ()
489537
0 commit comments