Skip to content

Commit

Permalink
expand branch specs
Browse files Browse the repository at this point in the history
  • Loading branch information
CKolkey committed Jul 29, 2023
1 parent d073bb5 commit da0fed0
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
47 changes: 47 additions & 0 deletions tests/specs/neogit/operations_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ local harness = require("tests.util.git_harness")
local in_prepared_repo = harness.in_prepared_repo
local get_current_branch = harness.get_current_branch
local get_git_branches = harness.get_git_branches
local get_git_rev = harness.get_git_rev
local util = require("tests.util.util")

local FuzzyFinderBuffer = require("tests.mocks.fuzzy_finder")
local status = require("neogit.status")
Expand Down Expand Up @@ -58,4 +60,49 @@ describe("branch popup", function()
assert.True(vim.tbl_contains(get_git_branches(), "branch-from-test-create"))
end)
)

it(
"can rename a branch",
in_prepared_repo(function()
FuzzyFinderBuffer.value = "second-branch"
input.value = "second-branch-renamed"

act("bm<cr><cr>")
operations.wait("rename_branch")
eq(true, vim.tbl_contains(get_git_branches(), "second-branch-renamed"))
eq(false, vim.tbl_contains(get_git_branches(), "second-branch"))
end)
)

it(
"can reset a branch",
in_prepared_repo(function()
util.system([[
git config user.email "[email protected]"
git config user.name "Neogit Test"
]])

FuzzyFinderBuffer.value = "second-branch"

util.system("git commit --allow-empty -m 'test'")
assert.are.Not.same("e2c2a1c0e5858a690c1dc13edc1fd5de103409d9", get_git_rev("HEAD"))

act("bXy<cr>")
operations.wait("reset_branch")
assert.are.same("e2c2a1c0e5858a690c1dc13edc1fd5de103409d9", get_git_rev("HEAD"))

assert.are.same('e2c2a1c HEAD@{0}: "reset: moving to second-branch"\n', util.system("git reflog -n1"))
end)
)

it(
"can delete a branch",
in_prepared_repo(function()
FuzzyFinderBuffer.value = "second-branch"

act("bD<cr>")
operations.wait("delete_branch")
eq(false, vim.tbl_contains(get_git_branches(), "second-branch"))
end)
)
end)
6 changes: 6 additions & 0 deletions tests/util/git_harness.lua
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,10 @@ function M.get_current_branch()
return lines[#lines - 1]
end

function M.get_git_rev(rev)
local result = vim.api.nvim_exec("!git rev-parse " .. rev, true)
local lines = vim.split(result, "\n")
return lines[3]
end

return M

0 comments on commit da0fed0

Please sign in to comment.