diff --git a/docs/keybindings/Keybindings_en.md b/docs/keybindings/Keybindings_en.md index 8edeb42bccb..243dff7e8c8 100644 --- a/docs/keybindings/Keybindings_en.md +++ b/docs/keybindings/Keybindings_en.md @@ -349,6 +349,7 @@ If you would instead like to start an interactive rebase from the selected commi | `` d `` | Delete | View delete options for local/remote tag. | | `` P `` | Push tag | Push the selected tag to a remote. You'll be prompted to select a remote. | | `` g `` | Reset | View reset options (soft/mixed/hard) for resetting onto selected item. | +| `` M `` | Merge | Merge selected tag into currently checked out branch | | `` `` | View commits | | | `` w `` | View worktree options | | | `` / `` | Filter the current view by text | | diff --git a/docs/keybindings/Keybindings_ja.md b/docs/keybindings/Keybindings_ja.md index 359972acecb..ba6177948dd 100644 --- a/docs/keybindings/Keybindings_ja.md +++ b/docs/keybindings/Keybindings_ja.md @@ -183,6 +183,7 @@ If you would instead like to start an interactive rebase from the selected commi | `` d `` | Delete | View delete options for local/remote tag. | | `` P `` | タグをpush | Push the selected tag to a remote. You'll be prompted to select a remote. | | `` g `` | Reset | View reset options (soft/mixed/hard) for resetting onto selected item. | +| `` M `` | 現在のブランチにマージ | Merge selected tag into currently checked out branch | | `` `` | コミットを閲覧 | | | `` w `` | View worktree options | | | `` / `` | Filter the current view by text | | diff --git a/docs/keybindings/Keybindings_ko.md b/docs/keybindings/Keybindings_ko.md index 1313ad9d3e4..59405733a34 100644 --- a/docs/keybindings/Keybindings_ko.md +++ b/docs/keybindings/Keybindings_ko.md @@ -322,6 +322,7 @@ If you would instead like to start an interactive rebase from the selected commi | `` d `` | Delete | View delete options for local/remote tag. | | `` P `` | 태그를 push | Push the selected tag to a remote. You'll be prompted to select a remote. | | `` g `` | Reset | View reset options (soft/mixed/hard) for resetting onto selected item. | +| `` M `` | 현재 브랜치에 병합 | Merge selected tag into currently checked out branch | | `` `` | 커밋 보기 | | | `` w `` | View worktree options | | | `` / `` | Filter the current view by text | | diff --git a/docs/keybindings/Keybindings_nl.md b/docs/keybindings/Keybindings_nl.md index 542786192fc..4703851de83 100644 --- a/docs/keybindings/Keybindings_nl.md +++ b/docs/keybindings/Keybindings_nl.md @@ -349,6 +349,7 @@ If you would instead like to start an interactive rebase from the selected commi | `` d `` | Delete | View delete options for local/remote tag. | | `` P `` | Push tag | Push the selected tag to a remote. You'll be prompted to select a remote. | | `` g `` | Reset | View reset options (soft/mixed/hard) for resetting onto selected item. | +| `` M `` | Merge in met huidige checked out branch | Merge selected tag into currently checked out branch | | `` `` | Bekijk commits | | | `` w `` | View worktree options | | | `` / `` | Filter the current view by text | | diff --git a/docs/keybindings/Keybindings_pl.md b/docs/keybindings/Keybindings_pl.md index e41c07e4d0e..e08025e444c 100644 --- a/docs/keybindings/Keybindings_pl.md +++ b/docs/keybindings/Keybindings_pl.md @@ -331,6 +331,7 @@ Jeśli chcesz zamiast tego rozpocząć interaktywny rebase od wybranego commita, | `` d `` | Usuń | Wyświetl opcje usuwania lokalnego/odległego tagu. | | `` P `` | Wyślij tag | Wyślij wybrany tag do zdalnego. Zostaniesz poproszony o wybranie zdalnego. | | `` g `` | Reset | Wyświetl opcje resetu (miękki/mieszany/twardy) do wybranego elementu. | +| `` M `` | Scal | Merge selected tag into currently checked out branch | | `` `` | Pokaż commity | | | `` w `` | Zobacz opcje drzewa pracy | | | `` / `` | Filtruj bieżący widok po tekście | | diff --git a/docs/keybindings/Keybindings_ru.md b/docs/keybindings/Keybindings_ru.md index c83652ee980..83851b92a24 100644 --- a/docs/keybindings/Keybindings_ru.md +++ b/docs/keybindings/Keybindings_ru.md @@ -288,6 +288,7 @@ If you would instead like to start an interactive rebase from the selected commi | `` d `` | Delete | View delete options for local/remote tag. | | `` P `` | Отправить тег | Push the selected tag to a remote. You'll be prompted to select a remote. | | `` g `` | Reset | View reset options (soft/mixed/hard) for resetting onto selected item. | +| `` M `` | Слияние с текущей переключённой веткой | Merge selected tag into currently checked out branch | | `` `` | Просмотреть коммиты | | | `` w `` | View worktree options | | | `` / `` | Filter the current view by text | | diff --git a/docs/keybindings/Keybindings_zh-CN.md b/docs/keybindings/Keybindings_zh-CN.md index e0f3a819c2e..647ee4a94b7 100644 --- a/docs/keybindings/Keybindings_zh-CN.md +++ b/docs/keybindings/Keybindings_zh-CN.md @@ -248,6 +248,7 @@ If you would instead like to start an interactive rebase from the selected commi | `` d `` | Delete | View delete options for local/remote tag. | | `` P `` | 推送标签 | Push the selected tag to a remote. You'll be prompted to select a remote. | | `` g `` | Reset | View reset options (soft/mixed/hard) for resetting onto selected item. | +| `` M `` | 合并到当前检出的分支 | Merge selected tag into currently checked out branch | | `` `` | 查看提交 | | | `` w `` | View worktree options | | | `` / `` | Filter the current view by text | | diff --git a/docs/keybindings/Keybindings_zh-TW.md b/docs/keybindings/Keybindings_zh-TW.md index 5457b05d233..218fbf420e1 100644 --- a/docs/keybindings/Keybindings_zh-TW.md +++ b/docs/keybindings/Keybindings_zh-TW.md @@ -284,6 +284,7 @@ If you would instead like to start an interactive rebase from the selected commi | `` d `` | Delete | View delete options for local/remote tag. | | `` P `` | 推送標籤 | Push the selected tag to a remote. You'll be prompted to select a remote. | | `` g `` | Reset | View reset options (soft/mixed/hard) for resetting onto selected item. | +| `` M `` | 合併到當前檢出的分支 | Merge selected tag into currently checked out branch | | `` `` | 檢視提交 | | | `` w `` | 檢視工作目錄選項 | | | `` / `` | 搜尋 | | diff --git a/pkg/gui/controllers/branches_controller.go b/pkg/gui/controllers/branches_controller.go index d7faa78118d..c01cab00ebc 100644 --- a/pkg/gui/controllers/branches_controller.go +++ b/pkg/gui/controllers/branches_controller.go @@ -595,7 +595,7 @@ func (self *BranchesController) delete(branch *models.Branch) error { func (self *BranchesController) merge() error { selectedBranchName := self.context().GetSelected().Name - return self.c.Helpers().MergeAndRebase.MergeRefIntoCheckedOutBranch(selectedBranchName) + return self.c.Helpers().MergeAndRebase.MergeRefIntoCheckedOutBranch(selectedBranchName, nil) } func (self *BranchesController) rebase() error { diff --git a/pkg/gui/controllers/helpers/merge_and_rebase_helper.go b/pkg/gui/controllers/helpers/merge_and_rebase_helper.go index 4bffcfa99ee..9feabaa4773 100644 --- a/pkg/gui/controllers/helpers/merge_and_rebase_helper.go +++ b/pkg/gui/controllers/helpers/merge_and_rebase_helper.go @@ -297,7 +297,7 @@ func (self *MergeAndRebaseHelper) RebaseOntoRef(ref string) error { }) } -func (self *MergeAndRebaseHelper) MergeRefIntoCheckedOutBranch(refName string) error { +func (self *MergeAndRebaseHelper) MergeRefIntoCheckedOutBranch(refName string, confirmCallback func() error) error { if self.c.Git().Branch.IsHeadDetached() { return errors.New("Cannot merge branch in detached head state. You might have checked out a commit directly or a remote branch, in which case you should checkout the local branch you want to be on") } @@ -319,7 +319,11 @@ func (self *MergeAndRebaseHelper) MergeRefIntoCheckedOutBranch(refName string) e HandleConfirm: func() error { self.c.LogAction(self.c.Tr.Actions.Merge) err := self.c.Git().Branch.Merge(refName, git_commands.MergeOpts{}) - return self.CheckMergeOrRebase(err) + err = self.CheckMergeOrRebase(err) + if err != nil || confirmCallback == nil { + return err + } + return confirmCallback() }, }) } diff --git a/pkg/gui/controllers/remote_branches_controller.go b/pkg/gui/controllers/remote_branches_controller.go index 97dbf56b00e..8d69bd871b3 100644 --- a/pkg/gui/controllers/remote_branches_controller.go +++ b/pkg/gui/controllers/remote_branches_controller.go @@ -129,7 +129,7 @@ func (self *RemoteBranchesController) delete(selectedBranch *models.RemoteBranch } func (self *RemoteBranchesController) merge(selectedBranch *models.RemoteBranch) error { - return self.c.Helpers().MergeAndRebase.MergeRefIntoCheckedOutBranch(selectedBranch.FullName()) + return self.c.Helpers().MergeAndRebase.MergeRefIntoCheckedOutBranch(selectedBranch.FullName(), nil) } func (self *RemoteBranchesController) rebase(selectedBranch *models.RemoteBranch) error { diff --git a/pkg/gui/controllers/tags_controller.go b/pkg/gui/controllers/tags_controller.go index d845f192d49..1b5decfbfbf 100644 --- a/pkg/gui/controllers/tags_controller.go +++ b/pkg/gui/controllers/tags_controller.go @@ -74,6 +74,13 @@ func (self *TagsController) GetKeybindings(opts types.KeybindingsOpts) []*types. DisplayOnScreen: true, OpensMenu: true, }, + { + Key: opts.GetKey(opts.Config.Branches.MergeIntoCurrentBranch), + Handler: opts.Guards.OutsideFilterMode(self.withItem(self.merge)), + Description: self.c.Tr.Merge, + Tooltip: self.c.Tr.MergeTagTooltip, + DisplayOnScreen: true, + }, } return bindings @@ -236,6 +243,18 @@ func (self *TagsController) create() error { }) } +func (self *TagsController) merge(tag *models.Tag) error { + err := self.c.Helpers().MergeAndRebase.MergeRefIntoCheckedOutBranch(tag.RefName(), func() error { + // Pass callback to swap to branches view on confirmation. + context, ok := self.c.Helpers().View.ContextForView(self.c.Views().Branches.Name()) + if !ok { + return nil + } + return self.c.PushContext(context) + }) + return err +} + func (self *TagsController) context() *context.TagsContext { return self.c.Contexts().Tags } diff --git a/pkg/i18n/english.go b/pkg/i18n/english.go index caa920de1ff..472157d823e 100644 --- a/pkg/i18n/english.go +++ b/pkg/i18n/english.go @@ -227,6 +227,7 @@ type TranslationSet struct { RefreshFiles string Merge string MergeBranchTooltip string + MergeTagTooltip string ConfirmQuit string SwitchRepo string AllBranchesLogGraph string @@ -1189,6 +1190,7 @@ func EnglishTranslationSet() TranslationSet { RefreshFiles: `Refresh files`, Merge: `Merge`, MergeBranchTooltip: "Merge selected branch into currently checked out branch.", + MergeTagTooltip: "Merge selected tag into currently checked out branch", ConfirmQuit: `Are you sure you want to quit?`, SwitchRepo: `Switch to a recent repo`, AllBranchesLogGraph: `Show all branch logs`, diff --git a/pkg/integration/tests/tag/merge.go b/pkg/integration/tests/tag/merge.go new file mode 100644 index 00000000000..14d46ebf683 --- /dev/null +++ b/pkg/integration/tests/tag/merge.go @@ -0,0 +1,39 @@ +package tag + +import ( + "github.com/jesseduffield/lazygit/pkg/config" + . "github.com/jesseduffield/lazygit/pkg/integration/components" +) + +var Merge = NewIntegrationTest(NewIntegrationTestArgs{ + Description: "Checkout a tag", + ExtraCmdArgs: []string{}, + Skip: false, + SetupConfig: func(config *config.AppConfig) {}, + SetupRepo: func(shell *Shell) { + shell.CreateFileAndAdd("test.txt", "1") + shell.Commit("first") + shell.NewBranch("tagbranch") + shell.UpdateFile("test.txt", "2") + shell.GitAddAll() + shell.Commit("tagcommit") + shell.CreateLightweightTag("tag", "HEAD") + shell.Checkout("master") + }, + Run: func(t *TestDriver, keys config.KeybindingConfig) { + // Merge tag via UI + t.Views().Tags(). + Focus(). + Lines( + Contains("tag").IsSelected(), + ).Press(keys.Branches.MergeIntoCurrentBranch) + t.Views().Confirmation().PressEnter() + // Assertions + t.Git().TagNamesAt("master", []string{"tag"}) + t.Views().Branches().IsFocused() + t.Views().Commits().TopLines( + Contains("tagcommit"), + Contains("first"), + ) + }, +}) diff --git a/pkg/integration/tests/test_list.go b/pkg/integration/tests/test_list.go index c65db5abcdc..040b05edbd1 100644 --- a/pkg/integration/tests/test_list.go +++ b/pkg/integration/tests/test_list.go @@ -300,6 +300,7 @@ var tests = []*components.IntegrationTest{ tag.CrudLightweight, tag.ForceTagAnnotated, tag.ForceTagLightweight, + tag.Merge, tag.Reset, ui.Accordion, ui.DoublePopup,