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 230550f
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 4 deletions.
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()
}
37 changes: 33 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,33 @@ func (self *FilesController) createStashMenu() error {
})
}

func (self *FilesController) createMergeConflictToolMenu() error {
return self.c.Menu(types.CreateMenuOptions{
Title: self.c.Tr.ViewMergeConflictOptionsTooltip,
Items: []*types.MenuItem{
{
Label: self.c.Tr.OpenMergeTool,
OnPress: self.c.Helpers().WorkingTree.OpenMergeTool,
Key: 'm',
},
{
Label: self.c.Tr.CheckoutOurs,
OnPress: func() error {
return self.c.Git().WorkingTree.CheckoutOurs(self.context().GetSelected().Name())
},
Key: 'o',
},
{
Label: self.c.Tr.CheckoutTheirs,
OnPress: func() error {
return self.c.Git().WorkingTree.CheckoutTheirs(self.context().GetSelected().Name())
},
Key: 't',
},
},
})
}

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

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

type Bisect struct {
Expand Down Expand Up @@ -1740,6 +1744,10 @@ 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.",
CheckoutOurs: "Checkout ours",
CheckoutTheirs: "Checkout theirs",

Actions: Actions{
// TODO: combine this with the original keybinding descriptions (those are all in lowercase atm)
Expand Down

0 comments on commit 230550f

Please sign in to comment.