From b38e7ebd856743538db8a15d845261f31410be0e Mon Sep 17 00:00:00 2001 From: Cameron Date: Thu, 13 Jul 2023 08:30:46 +0200 Subject: [PATCH] Revert "Revert "expand on branch popup spec"" This reverts commit 289b6c5ef8d391a1699ce4ebab46497c2e4963f3. --- tests/.repo/.git.orig/config | 11 +++ tests/.repo/.git.orig/index | Bin 190 -> 295 bytes tests/branch_popup_spec.lua | 148 +++++++++++++++++++++++++++-------- tests/git_harness.lua | 12 +++ 4 files changed, 140 insertions(+), 31 deletions(-) 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 cc45273780ebeb6bbf35c25f5bc90050d5a8f4cd..7ce0add9199fab92d4e95def3db64202e48fb624 100644 GIT binary patch literal 295 zcmZ?q402{*U|@n`AcYMyE*ptROW90r){VBMMb@{hRyxjG!N8iRS5i>|R+h5v zuMKPB90wT9$iN`Ps_%4!fdOO=<5!>}5gfx&qZnG8icsa0&DMUo@k6#w*#NzcyLLrX(bBU3#COJf5Q<0vajpkf9YAO^Y$!`mP+hAR_3t6aW+ SPbeU`F1FCJHJE z7EFGYIZP8_G(@dvIkMV`7248l47!F223%|NGmaMS)ldreRGCouoVU%)u`vk%uxKG@ 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 a0671676b..c7ff0ddbf 100644 --- a/tests/git_harness.lua +++ b/tests/git_harness.lua @@ -71,6 +71,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")