diff --git a/tests/.repo/.git.orig/config b/tests/.repo/.git.orig/config index 515f48362..576d19be5 100644 --- a/tests/.repo/.git.orig/config +++ b/tests/.repo/.git.orig/config @@ -3,3 +3,14 @@ filemode = true bare = false logallrefupdates = true +[remote "origin"] + url = git@github.com:NeogitOrg/neogit.git + fetch = +refs/heads/*:refs/remotes/origin/* +[remote "fake"] + url = git@github.com:NeogitOrgFake/neogit.git + fetch = +refs/heads/*:refs/remotes/fake/* +[branch "master"] + remote = origin + pushRemote = origin + merge = refs/heads/master + rebase = true diff --git a/tests/.repo/.git.orig/index b/tests/.repo/.git.orig/index index cc4527378..7ce0add91 100644 Binary files a/tests/.repo/.git.orig/index and b/tests/.repo/.git.orig/index differ diff --git a/tests/branch_popup_spec.lua b/tests/branch_popup_spec.lua index d78321720..e1736cbb1 100644 --- a/tests/branch_popup_spec.lua +++ b/tests/branch_popup_spec.lua @@ -1,49 +1,135 @@ require("plenary.async").tests.add_to_env() + local eq = assert.are.same local operations = require("neogit.operations") + local harness = require("tests.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 FuzzyFinderBuffer = require("tests.mocks.fuzzy_finder") -local status = require("neogit.status") local input = require("tests.mocks.input") local function act(normal_cmd) print("Feeding keys: ", normal_cmd) vim.fn.feedkeys(vim.api.nvim_replace_termcodes(normal_cmd, true, true, true)) vim.fn.feedkeys("", "x") -- flush typeahead - status.wait_on_current_operation() end describe("branch popup", function() - it( - "can switch to another branch in the repository", - in_prepared_repo(function() - FuzzyFinderBuffer.value = "second-branch" - act("bb") - operations.wait("checkout_branch_revision") - eq("second-branch", get_current_branch()) - end) - ) - - it( - "can switch to another local branch in the repository", - in_prepared_repo(function() - FuzzyFinderBuffer.value = "second-branch" - act("bl") - operations.wait("checkout_branch_local") - eq("second-branch", get_current_branch()) - end) - ) - - it( - "can create a new branch", - in_prepared_repo(function() - input.value = "branch-from-test" - act("bc") - operations.wait("checkout_create_branch") - eq("branch-from-test", get_current_branch()) - end) - ) + describe("actions", function() + it( + "can switch to another branch in the repository", + in_prepared_repo(function() + FuzzyFinderBuffer.value = "second-branch" + act("bb") + operations.wait("checkout_branch_revision") + eq("second-branch", get_current_branch()) + end) + ) + + it( + "can switch to another local branch in the repository", + in_prepared_repo(function() + FuzzyFinderBuffer.value = "second-branch" + act("bl") + operations.wait("checkout_branch_local") + eq("second-branch", get_current_branch()) + end) + ) + + it( + "can create a new branch", + in_prepared_repo(function() + input.value = "branch-from-test" + act("bc") + operations.wait("checkout_create_branch") + eq("branch-from-test", get_current_branch()) + end) + ) + + it( + "can create a new branch without checking it out", + in_prepared_repo(function() + input.value = "branch-from-test-create" + act("bn") + operations.wait("create_branch") + eq("master", get_current_branch()) + eq(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() + FuzzyFinderBuffer.value = "third-branch" + + eq("e2c2a1c0e5858a690c1dc13edc1fd5de103409d9", get_git_rev("HEAD")) + act("bXy") + operations.wait("reset_branch") + eq("1e9b765da30ad45ef0b863470c73104bb7161e23", get_git_rev("HEAD")) + end) + ) + + it( + "can delete a branch", + in_prepared_repo(function() + FuzzyFinderBuffer.value = "third-branch" + + act("bD") + operations.wait("delete_branch") + eq(false, vim.tbl_contains(get_git_branches(), "third-branch")) + end) + ) + end) + + describe("variables", function() + -- it("can change branch.*.description", in_prepared_repo(function() + -- input.value = "branch description" + -- act("bd") + -- eq("branch description", harness.get_git_config("branch.master.description")) + -- end)) + + it( + "can change branch.*.merge", + in_prepared_repo(function() + FuzzyFinderBuffer.value = "second-branch" + + eq("refs/heads/master", harness.get_git_config("branch.master.merge")) + act("bu") + eq("refs/heads/second-branch", harness.get_git_config("branch.master.merge")) + end) + ) + + -- it( + -- "can change branch.*.rebase", + -- in_prepared_repo(function() + -- eq("true", harness.get_git_config("branch.master.rebase")) + -- act("br") + -- eq("false", harness.get_git_config("branch.master.rebase")) + -- end) + -- ) + + -- it( + -- "can change branch.*.pushRemote", + -- in_prepared_repo(function() + -- act("bp") + -- end) + -- ) + end) end) diff --git a/tests/git_harness.lua b/tests/git_harness.lua index 84f20d8cf..ede55f27f 100644 --- a/tests/git_harness.lua +++ b/tests/git_harness.lua @@ -72,6 +72,18 @@ function M.get_git_diff(files, flags) return table.concat(output, "\n") 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 + +function M.get_git_config(var) + local result = vim.api.nvim_exec("!git config --get --local " .. var, true) + local lines = vim.split(result, "\n") + return lines[3] +end + function M.get_git_branches() local result = vim.api.nvim_exec("!git branch --list --all", true) local lines = vim.split(result, "\n")