Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added failing unit test for most common case; switching while file not in cwd #40

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Binary file modified tests/repo_origin/.git-orig/index
Binary file not shown.
1 change: 1 addition & 0 deletions tests/repo_origin/.git-orig/logs/refs/heads/featD
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0000000000000000000000000000000000000000 2afa41f6d9a4e4dc25e9088e402fe7ba35b95a10 Tama McGlinn <[email protected]> 1626674130 +0200 branch: Created from master
1 change: 1 addition & 0 deletions tests/repo_origin/.git-orig/refs/heads/featD
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2afa41f6d9a4e4dc25e9088e402fe7ba35b95a10
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