diff --git a/tests/specs/neogit/operations_spec.lua b/tests/specs/neogit/operations_spec.lua index ab0535cf2..c742cc6e3 100644 --- a/tests/specs/neogit/operations_spec.lua +++ b/tests/specs/neogit/operations_spec.lua @@ -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") @@ -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") + 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 "test@neogit-test.test" + 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") + 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") + operations.wait("delete_branch") + eq(false, vim.tbl_contains(get_git_branches(), "second-branch")) + end) + ) end) diff --git a/tests/util/git_harness.lua b/tests/util/git_harness.lua index 4837e97d1..c63c329ab 100644 --- a/tests/util/git_harness.lua +++ b/tests/util/git_harness.lua @@ -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