Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Merge keybind in tag submenu, closes #1315 #3383

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/keybindings/Keybindings_en.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
| `` <enter> `` | View commits | |
| `` w `` | View worktree options | |
| `` / `` | Filter the current view by text | |
Expand Down
1 change: 1 addition & 0 deletions docs/keybindings/Keybindings_ja.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
| `` <enter> `` | コミットを閲覧 | |
| `` w `` | View worktree options | |
| `` / `` | Filter the current view by text | |
Expand Down
1 change: 1 addition & 0 deletions docs/keybindings/Keybindings_ko.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
| `` <enter> `` | 커밋 보기 | |
| `` w `` | View worktree options | |
| `` / `` | Filter the current view by text | |
Expand Down
1 change: 1 addition & 0 deletions docs/keybindings/Keybindings_nl.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
| `` <enter> `` | Bekijk commits | |
| `` w `` | View worktree options | |
| `` / `` | Filter the current view by text | |
Expand Down
1 change: 1 addition & 0 deletions docs/keybindings/Keybindings_pl.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
| `` <enter> `` | Pokaż commity | |
| `` w `` | Zobacz opcje drzewa pracy | |
| `` / `` | Filtruj bieżący widok po tekście | |
Expand Down
1 change: 1 addition & 0 deletions docs/keybindings/Keybindings_ru.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
| `` <enter> `` | Просмотреть коммиты | |
| `` w `` | View worktree options | |
| `` / `` | Filter the current view by text | |
Expand Down
1 change: 1 addition & 0 deletions docs/keybindings/Keybindings_zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
| `` <enter> `` | 查看提交 | |
| `` w `` | View worktree options | |
| `` / `` | Filter the current view by text | |
Expand Down
1 change: 1 addition & 0 deletions docs/keybindings/Keybindings_zh-TW.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
| `` <enter> `` | 檢視提交 | |
| `` w `` | 檢視工作目錄選項 | |
| `` / `` | 搜尋 | |
Expand Down
2 changes: 1 addition & 1 deletion pkg/gui/controllers/branches_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 6 additions & 2 deletions pkg/gui/controllers/helpers/merge_and_rebase_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand All @@ -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()
},
})
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/gui/controllers/remote_branches_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
19 changes: 19 additions & 0 deletions pkg/gui/controllers/tags_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
2 changes: 2 additions & 0 deletions pkg/i18n/english.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ type TranslationSet struct {
RefreshFiles string
Merge string
MergeBranchTooltip string
MergeTagTooltip string
ConfirmQuit string
SwitchRepo string
AllBranchesLogGraph string
Expand Down Expand Up @@ -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`,
Expand Down
39 changes: 39 additions & 0 deletions pkg/integration/tests/tag/merge.go
Original file line number Diff line number Diff line change
@@ -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"),
)
},
})
1 change: 1 addition & 0 deletions pkg/integration/tests/test_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,7 @@ var tests = []*components.IntegrationTest{
tag.CrudLightweight,
tag.ForceTagAnnotated,
tag.ForceTagLightweight,
tag.Merge,
tag.Reset,
ui.Accordion,
ui.DoublePopup,
Expand Down