Skip to content

Commit

Permalink
Added failing unit test for most common case; switching while file no…
Browse files Browse the repository at this point in the history
…t in cwd
  • Loading branch information
TamaMcGlinn committed May 5, 2021
1 parent 4b990cc commit 86a8fe4
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 0 deletions.
29 changes: 29 additions & 0 deletions tests/git_harness.lua
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,35 @@ M.in_bare_repo_from_origin_2_worktrees = function(cb)
end
end

M.in_bare_repo_from_origin_3_worktrees = function(cb)
return function()
local random_id = random_string()
local origin_repo_dir = 'git_worktree_test_origin_repo_' .. random_id
local bare_repo_dir = 'git_worktree_test_repo_' .. random_id

config_git_worktree()
cleanup_repos()

prepare_origin_repo(origin_repo_dir)
prepare_bare_repo(bare_repo_dir, origin_repo_dir)
change_dir(bare_repo_dir)
create_worktree('featB','featB')
create_worktree('featC','featC')
create_worktree('featD','featD')

local _, err = pcall(cb)

reset_cwd()

cleanup_repos()

if err ~= nil then
error(err)
end

end
end

M.in_repo_from_origin_2_worktrees = function(cb)
return function()
local random_id = random_string()
Expand Down
48 changes: 48 additions & 0 deletions tests/worktree_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ local in_bare_repo_from_origin_1_worktree = harness.in_bare_repo_from_origin_1_w
local in_repo_from_origin_1_worktree = harness.in_repo_from_origin_1_worktree
local in_repo_from_local_no_worktrees = harness.in_repo_from_local_no_worktrees
local in_bare_repo_from_origin_2_worktrees = harness.in_bare_repo_from_origin_2_worktrees
local in_bare_repo_from_origin_3_worktrees = harness.in_bare_repo_from_origin_3_worktrees
local in_repo_from_origin_2_worktrees = harness.in_repo_from_origin_2_worktrees
local check_git_worktree_exists = harness.check_git_worktree_exists
local check_branch_upstream = harness.check_branch_upstream
Expand Down Expand Up @@ -484,6 +485,53 @@ describe('git-worktree', function()
assert.True(featC_abs_A_path == get_current_file())
end))

it('in a featB worktree(bare) with file A inside featC open, switch to featD and switch to file A in other worktree',
in_bare_repo_from_origin_3_worktrees(function()

local featB_path = "featB"
local featB_abs_path = git_worktree:get_root() .. Path.path.sep .. featB_path
local featB_abs_A_path = featB_abs_path .. Path.path.sep .. "A.txt"

local featC_path = "featC"
local featC_abs_path = git_worktree:get_root() .. Path.path.sep .. featC_path
local featC_abs_A_path = featC_abs_path .. Path.path.sep .. "A.txt"

local featD_path = "featD"
local featD_abs_path = git_worktree:get_root() .. Path.path.sep .. featD_path
local featD_abs_A_path = featD_abs_path .. Path.path.sep .. "A.txt"

-- switch to featB worktree
git_worktree.switch_worktree(featB_path)

vim.fn.wait(
10000,
function()
return completed_switch
end,
1000
)

-- open A file
vim.cmd("e ../featC/A.txt")
-- make sure it is opened
assert.True(featC_abs_A_path == get_current_file())

-- switch to featD worktree
reset_variables()
git_worktree.switch_worktree(featD_path)

vim.fn.wait(
10000,
function()
return completed_switch
end,
1000
)

-- make sure it switch to file in other tree
assert.True(featD_abs_A_path == get_current_file())
end))

it('in a featB worktree(non bare) with file A open, switch to featC and switch to file A in other worktree',
in_repo_from_origin_2_worktrees(function()

Expand Down

0 comments on commit 86a8fe4

Please sign in to comment.