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 new file mode 100644 index 00000000000..73e597f8f41 --- /dev/null +++ b/pkg/integration/tests/tag/checkout_when_branch_with_same_name_exists.go @@ -0,0 +1,34 @@ +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( + Contains("HEAD detached at tag").IsSelected(), + Contains("master"), + Contains("tag"), + ) + }, +}) 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,