Skip to content

Commit

Permalink
Add new merge conflicts menu and move the previous external merge too…
Browse files Browse the repository at this point in the history
…l there

Also add options for `git checkout --theirs` and `git checkout --ours`

Fixes jesseduffield#2026
  • Loading branch information
recht committed Apr 5, 2024
1 parent 53f0c4a commit 48c88f9
Show file tree
Hide file tree
Showing 13 changed files with 111 additions and 12 deletions.
2 changes: 1 addition & 1 deletion docs/keybindings/Keybindings_en.md
Expand Up @@ -143,7 +143,7 @@ If you would instead like to start an interactive rebase from the selected commi
| `` D `` | Reset | View reset options for working tree (e.g. nuking the working tree). |
| `` ` `` | Toggle file tree view | Toggle file view between flat and tree layout. Flat layout shows all file paths in a single list, tree layout groups files by directory. |
| `` <c-t> `` | Open external diff tool (git difftool) | |
| `` M `` | Open external merge tool | Run `git mergetool`. |
| `` M `` | View merge conflict options | View options for resolving merge conflicts. |
| `` f `` | Fetch | Fetch changes from remote. |
| `` / `` | Search the current view by text | |

Expand Down
2 changes: 1 addition & 1 deletion docs/keybindings/Keybindings_ja.md
Expand Up @@ -213,7 +213,7 @@ If you would instead like to start an interactive rebase from the selected commi
| `` D `` | Reset | View reset options for working tree (e.g. nuking the working tree). |
| `` ` `` | ファイルツリーの表示を切り替え | Toggle file view between flat and tree layout. Flat layout shows all file paths in a single list, tree layout groups files by directory. |
| `` <c-t> `` | Open external diff tool (git difftool) | |
| `` M `` | Git mergetoolを開く | Run `git mergetool`. |
| `` M `` | View merge conflict options | View options for resolving merge conflicts. |
| `` f `` | Fetch | Fetch changes from remote. |
| `` / `` | 検索を開始 | |

Expand Down
2 changes: 1 addition & 1 deletion docs/keybindings/Keybindings_ko.md
Expand Up @@ -352,7 +352,7 @@ If you would instead like to start an interactive rebase from the selected commi
| `` D `` | Reset | View reset options for working tree (e.g. nuking the working tree). |
| `` ` `` | 파일 트리뷰로 전환 | Toggle file view between flat and tree layout. Flat layout shows all file paths in a single list, tree layout groups files by directory. |
| `` <c-t> `` | Open external diff tool (git difftool) | |
| `` M `` | Git mergetool를 열기 | Run `git mergetool`. |
| `` M `` | View merge conflict options | View options for resolving merge conflicts. |
| `` f `` | Fetch | Fetch changes from remote. |
| `` / `` | 검색 시작 | |

Expand Down
2 changes: 1 addition & 1 deletion docs/keybindings/Keybindings_nl.md
Expand Up @@ -75,7 +75,7 @@ _Legend: `<c-b>` means ctrl+b, `<a-b>` means alt+b, `B` means shift+b_
| `` D `` | Reset | View reset options for working tree (e.g. nuking the working tree). |
| `` ` `` | Toggle bestandsboom weergave | Toggle file view between flat and tree layout. Flat layout shows all file paths in a single list, tree layout groups files by directory. |
| `` <c-t> `` | Open external diff tool (git difftool) | |
| `` M `` | Open external merge tool | Run `git mergetool`. |
| `` M `` | View merge conflict options | View options for resolving merge conflicts. |
| `` f `` | Fetch | Fetch changes from remote. |
| `` / `` | Start met zoeken | |

Expand Down
2 changes: 1 addition & 1 deletion docs/keybindings/Keybindings_pl.md
Expand Up @@ -224,7 +224,7 @@ Jeśli chcesz zamiast tego rozpocząć interaktywny rebase od wybranego commita,
| `` D `` | Reset | Wyświetl opcje resetu dla drzewa roboczego (np. zniszczenie drzewa roboczego). |
| `` ` `` | Przełącz widok drzewa plików | Przełącz widok plików między płaskim a drzewem. Płaski układ pokazuje wszystkie ścieżki plików na jednej liście, układ drzewa grupuje pliki według katalogów. |
| `` <c-t> `` | Otwórz zewnętrzne narzędzie różnic (git difftool) | |
| `` M `` | Otwórz zewnętrzne narzędzie scalania | Uruchom `git mergetool`. |
| `` M `` | View merge conflict options | View options for resolving merge conflicts. |
| `` f `` | Pobierz | Pobierz zmiany ze zdalnego serwera. |
| `` / `` | Szukaj w bieżącym widoku po tekście | |

Expand Down
2 changes: 1 addition & 1 deletion docs/keybindings/Keybindings_ru.md
Expand Up @@ -346,7 +346,7 @@ If you would instead like to start an interactive rebase from the selected commi
| `` D `` | Reset | View reset options for working tree (e.g. nuking the working tree). |
| `` ` `` | Переключить вид дерева файлов | Toggle file view between flat and tree layout. Flat layout shows all file paths in a single list, tree layout groups files by directory. |
| `` <c-t> `` | Open external diff tool (git difftool) | |
| `` M `` | Открыть внешний инструмент слияния (git mergetool) | Run `git mergetool`. |
| `` M `` | View merge conflict options | View options for resolving merge conflicts. |
| `` f `` | Получить изменения | Fetch changes from remote. |
| `` / `` | Найти | |

Expand Down
2 changes: 1 addition & 1 deletion docs/keybindings/Keybindings_zh-CN.md
Expand Up @@ -220,7 +220,7 @@ If you would instead like to start an interactive rebase from the selected commi
| `` D `` | Reset | View reset options for working tree (e.g. nuking the working tree). |
| `` ` `` | 切换文件树视图 | Toggle file view between flat and tree layout. Flat layout shows all file paths in a single list, tree layout groups files by directory. |
| `` <c-t> `` | Open external diff tool (git difftool) | |
| `` M `` | 打开外部合并工具 (git mergetool) | Run `git mergetool`. |
| `` M `` | View merge conflict options | View options for resolving merge conflicts. |
| `` f `` | 抓取 | Fetch changes from remote. |
| `` / `` | 开始搜索 | |

Expand Down
2 changes: 1 addition & 1 deletion docs/keybindings/Keybindings_zh-TW.md
Expand Up @@ -314,7 +314,7 @@ If you would instead like to start an interactive rebase from the selected commi
| `` D `` | Reset | View reset options for working tree (e.g. nuking the working tree). |
| `` ` `` | 顯示檔案樹狀視圖 | Toggle file view between flat and tree layout. Flat layout shows all file paths in a single list, tree layout groups files by directory. |
| `` <c-t> `` | Open external diff tool (git difftool) | |
| `` M `` | 開啟外部合併工具 (git mergetool) | Run `git mergetool`. |
| `` M `` | View merge conflict options | View options for resolving merge conflicts. |
| `` f `` | 擷取 | Fetch changes from remote. |
| `` / `` | 搜尋 | |

Expand Down
14 changes: 14 additions & 0 deletions pkg/commands/git_commands/working_tree.go
Expand Up @@ -385,3 +385,17 @@ func (self *WorkingTreeCommands) ResetMixed(ref string) error {

return self.cmd.New(cmdArgs).Run()
}

func (self *WorkingTreeCommands) CheckoutTheirs(name string) error {
cmdArgs := NewGitCmd("checkout").Arg("--theirs", "--", name).
ToArgv()

return self.cmd.New(cmdArgs).Run()
}

func (self *WorkingTreeCommands) CheckoutOurs(name string) error {
cmdArgs := NewGitCmd("checkout").Arg("--ours", "--", name).
ToArgv()

return self.cmd.New(cmdArgs).Run()
}
43 changes: 39 additions & 4 deletions pkg/gui/controllers/files_controller.go
Expand Up @@ -174,10 +174,12 @@ func (self *FilesController) GetKeybindings(opts types.KeybindingsOpts) []*types
Description: self.c.Tr.OpenDiffTool,
},
{
Key: opts.GetKey(opts.Config.Files.OpenMergeTool),
Handler: self.c.Helpers().WorkingTree.OpenMergeTool,
Description: self.c.Tr.OpenMergeTool,
Tooltip: self.c.Tr.OpenMergeToolTooltip,
Key: opts.GetKey(opts.Config.Files.OpenMergeTool),
Handler: self.createMergeConflictToolMenu,
Description: self.c.Tr.ViewMergeConflictOptions,
Tooltip: self.c.Tr.ViewMergeConflictOptionsTooltip,
OpensMenu: true,
DisplayOnScreen: true,
},
{
Key: opts.GetKey(opts.Config.Files.Fetch),
Expand Down Expand Up @@ -818,6 +820,39 @@ func (self *FilesController) createStashMenu() error {
})
}

func (self *FilesController) createMergeConflictToolMenu() error {
return self.c.Menu(types.CreateMenuOptions{
Title: self.c.Tr.MergeConflictOptions,
Items: []*types.MenuItem{
{
Label: self.c.Tr.OpenMergeTool,
OnPress: self.c.Helpers().WorkingTree.OpenMergeTool,
Key: 'm',
},
{
Label: self.c.Tr.CheckoutOurs,
OnPress: func() error {
if err := self.c.Git().WorkingTree.CheckoutOurs(self.context().GetSelected().GetPath()); err != nil {
return self.c.Error(err)
}
return nil
},
Key: 'o',
},
{
Label: self.c.Tr.CheckoutTheirs,
OnPress: func() error {
if err := self.c.Git().WorkingTree.CheckoutTheirs(self.context().GetSelected().GetPath()); err != nil {
return self.c.Error(err)
}
return nil
},
Key: 't',
},
},
})
}

func (self *FilesController) openCopyMenu() error {
node := self.context().GetSelected()

Expand Down
10 changes: 10 additions & 0 deletions pkg/i18n/english.go
Expand Up @@ -786,6 +786,11 @@ type TranslationSet struct {
BreakingChangesTitle string
BreakingChangesMessage string
BreakingChangesByVersion map[string]string
ViewMergeConflictOptions string
ViewMergeConflictOptionsTooltip string
MergeConflictOptions string
CheckoutOurs string
CheckoutTheirs string
}

type Bisect struct {
Expand Down Expand Up @@ -1740,6 +1745,11 @@ func EnglishTranslationSet() TranslationSet {
RangeSelectNotSupportedForSubmodules: "Range select not supported for submodules",
OldCherryPickKeyWarning: "The 'c' key is no longer the default key for copying commits to cherry pick. Please use `{{.copy}}` instead (and `{{.paste}}` to paste). The reason for this change is that the 'v' key for selecting a range of lines when staging is now also used for selecting a range of lines in any list view, meaning that we needed to find a new key for pasting commits, and if we're going to now use `{{.paste}}` for pasting commits, we may as well use `{{.copy}}` for copying them. If you want to configure the keybindings to get the old behaviour, set the following in your config:\n\nkeybinding:\n universal:\n toggleRangeSelect: <something other than v>\n commits:\n cherryPickCopy: 'c'\n pasteCommits: 'v'",
CommandDoesNotSupportOpeningInEditor: "This command doesn't support switching to the editor",
ViewMergeConflictOptions: "View merge conflict options",
ViewMergeConflictOptionsTooltip: "View options for resolving merge conflicts.",
MergeConflictOptions: "Merge conflict options",
CheckoutOurs: "Checkout ours",
CheckoutTheirs: "Checkout theirs",

Actions: Actions{
// TODO: combine this with the original keybinding descriptions (those are all in lowercase atm)
Expand Down
1 change: 1 addition & 0 deletions pkg/integration/tests/test_list.go
Expand Up @@ -303,6 +303,7 @@ var tests = []*components.IntegrationTest{
worktree.AssociateBranchRebase,
worktree.BareRepo,
worktree.BareRepoWorktreeConfig,
worktree.ConflictCheckoutTheirs,
worktree.Crud,
worktree.CustomCommand,
worktree.DetachWorktreeFromBranch,
Expand Down
39 changes: 39 additions & 0 deletions pkg/integration/tests/worktree/conflict_checkout_theirs.go
@@ -0,0 +1,39 @@
package worktree

import (
"github.com/jesseduffield/lazygit/pkg/config"
. "github.com/jesseduffield/lazygit/pkg/integration/components"
"github.com/jesseduffield/lazygit/pkg/integration/tests/shared"
)

var ConflictCheckoutTheirs = NewIntegrationTest(NewIntegrationTestArgs{
Description: "Conflicting file can be resolved by checkout out their version",
ExtraCmdArgs: []string{},
Skip: false,
SetupConfig: func(config *config.AppConfig) {},
SetupRepo: func(shell *Shell) {
shared.CreateMergeConflictFile(shell)
},
Run: func(t *TestDriver, keys config.KeybindingConfig) {
t.Views().Files().
IsFocused().
Lines(
Contains("UU file").IsSelected(),
).
Press(keys.Files.OpenMergeTool).
Tap(func() {
t.ExpectPopup().Menu().
Title(Equals("Merge conflict options")).
Select(Contains("Checkout theirs")).
Confirm()
}).
Press(keys.Universal.Refresh).
Tap(func() {
t.Common().ContinueOnConflictsResolved()
}).
IsEmpty()

// t.Views().Files().
// IsEmpty()
},
})

0 comments on commit 48c88f9

Please sign in to comment.