Fix checking out a tag when there is a branch with the same name (#3179)

This commit is contained in:
Stefan Haller
2024-01-09 14:23:08 +01:00
committed by GitHub
3 changed files with 36 additions and 1 deletions

View File

@@ -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)

View File

@@ -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"),
)
},
})

View File

@@ -245,6 +245,7 @@ var tests = []*components.IntegrationTest{
sync.PushWithCredentialPrompt,
sync.RenameBranchAndPull,
tag.Checkout,
tag.CheckoutWhenBranchWithSameNameExists,
tag.CreateWhileCommitting,
tag.CrudAnnotated,
tag.CrudLightweight,