From 2b97f0fb43481f04095ea2be465dbaba16b5264e Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Fri, 22 Dec 2023 15:28:53 +0100 Subject: [PATCH] Add test demonstrating the problem When there's a branch with the same name as the tag, the branch gets checked out instead of the tag. --- ...ckout_when_branch_with_same_name_exists.go | 38 +++++++++++++++++++ pkg/integration/tests/test_list.go | 1 + 2 files changed, 39 insertions(+) create mode 100644 pkg/integration/tests/tag/checkout_when_branch_with_same_name_exists.go diff --git a/pkg/integration/tests/tag/checkout_when_branch_with_same_name_exists.go b/pkg/integration/tests/tag/checkout_when_branch_with_same_name_exists.go new file mode 100644 index 000000000..2f291e29f --- /dev/null +++ b/pkg/integration/tests/tag/checkout_when_branch_with_same_name_exists.go @@ -0,0 +1,38 @@ +package tag + +import ( + "github.com/jesseduffield/lazygit/pkg/config" + . "github.com/jesseduffield/lazygit/pkg/integration/components" +) + +var CheckoutWhenBranchWithSameNameExists = NewIntegrationTest(NewIntegrationTestArgs{ + Description: "Checkout a tag when there's a branch with the same name", + ExtraCmdArgs: []string{}, + Skip: false, + SetupConfig: func(config *config.AppConfig) {}, + SetupRepo: func(shell *Shell) { + shell.EmptyCommit("one") + shell.NewBranch("tag") + shell.Checkout("master") + shell.EmptyCommit("two") + shell.CreateLightweightTag("tag", "HEAD") + }, + Run: func(t *TestDriver, keys config.KeybindingConfig) { + t.Views().Tags(). + Focus(). + Lines( + Contains("tag").IsSelected(), + ). + PressPrimaryAction() // checkout tag + + t.Views().Branches().IsFocused().Lines( + /* EXPECTED: + Contains("HEAD detached at tag").IsSelected(), + Contains("master"), + Contains("tag"), + ACTUAL: */ + Contains("* tag").DoesNotContain("HEAD detached").IsSelected(), + Contains("master"), + ) + }, +}) diff --git a/pkg/integration/tests/test_list.go b/pkg/integration/tests/test_list.go index ba2f8d6aa..c61a7c2e6 100644 --- a/pkg/integration/tests/test_list.go +++ b/pkg/integration/tests/test_list.go @@ -245,6 +245,7 @@ var tests = []*components.IntegrationTest{ sync.PushWithCredentialPrompt, sync.RenameBranchAndPull, tag.Checkout, + tag.CheckoutWhenBranchWithSameNameExists, tag.CreateWhileCommitting, tag.CrudAnnotated, tag.CrudLightweight,