From 2b97f0fb43481f04095ea2be465dbaba16b5264e Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Fri, 22 Dec 2023 15:28:53 +0100 Subject: [PATCH 1/2] 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 00000000000..2f291e29fc9 --- /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 ba2f8d6aa74..c61a7c2e6d7 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, From f244ec8251d77e41d02507811f49c388aa67a042 Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Fri, 22 Dec 2023 15:30:54 +0100 Subject: [PATCH 2/2] Fix checking out a tag when a branch with the same name exists --- pkg/gui/controllers/tags_controller.go | 2 +- .../tests/tag/checkout_when_branch_with_same_name_exists.go | 4 ---- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/pkg/gui/controllers/tags_controller.go b/pkg/gui/controllers/tags_controller.go index 224ad83a4be..dcbef4d2cfe 100644 --- a/pkg/gui/controllers/tags_controller.go +++ b/pkg/gui/controllers/tags_controller.go @@ -83,7 +83,7 @@ func (self *TagsController) GetOnRenderToMain() func() error { func (self *TagsController) checkout(tag *models.Tag) error { self.c.LogAction(self.c.Tr.Actions.CheckoutTag) - if err := self.c.Helpers().Refs.CheckoutRef(tag.Name, types.CheckoutRefOptions{}); err != nil { + if err := self.c.Helpers().Refs.CheckoutRef(tag.FullRefName(), types.CheckoutRefOptions{}); err != nil { return err } return self.c.PushContext(self.c.Contexts().Branches) 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 index 2f291e29fc9..73e597f8f41 100644 --- 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 @@ -26,13 +26,9 @@ var CheckoutWhenBranchWithSameNameExists = NewIntegrationTest(NewIntegrationTest 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"), ) }, })