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

Add git difftool support (keybinding <c-t>) #1846

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
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 @@ -17,6 +17,7 @@ _This file is auto-generated. To update, make the changes in the pkg/i18n direct
<kbd>ctrl+s</kbd>: view filter-by-path options
<kbd>W</kbd>: open diff menu
<kbd>ctrl+e</kbd>: open diff menu
<kbd>ctrl+t</kbd>: Launch git difftool
<kbd>@</kbd>: open command log menu
<kbd>}</kbd>: Increase the size of the context shown around changes in the diff view
<kbd>{</kbd>: Decrease the size of the context shown around changes in the diff view
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 @@ -17,6 +17,7 @@ _This file is auto-generated. To update, make the changes in the pkg/i18n direct
<kbd>ctrl+s</kbd>: bekijk scoping opties
<kbd>W</kbd>: open diff menu
<kbd>ctrl+e</kbd>: open diff menu
<kbd>ctrl+t</kbd>: Launch git difftool
<kbd>@</kbd>: open command log menu
<kbd>}</kbd>: Increase the size of the context shown around changes in the diff view
<kbd>{</kbd>: Decrease the size of the context shown around changes in the diff view
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 @@ -17,6 +17,7 @@ _This file is auto-generated. To update, make the changes in the pkg/i18n direct
<kbd>ctrl+s</kbd>: view filter-by-path options
<kbd>W</kbd>: open diff menu
<kbd>ctrl+e</kbd>: open diff menu
<kbd>ctrl+t</kbd>: Launch git difftool
<kbd>@</kbd>: open command log menu
<kbd>}</kbd>: Increase the size of the context shown around changes in the diff view
<kbd>{</kbd>: Decrease the size of the context shown around changes in the diff view
Expand Down
1 change: 1 addition & 0 deletions docs/keybindings/Keybindings_zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ _This file is auto-generated. To update, make the changes in the pkg/i18n direct
<kbd>ctrl+s</kbd>: 查看按路径过滤选项
<kbd>W</kbd>: 打开 diff 菜单
<kbd>ctrl+e</kbd>: 打开 diff 菜单
<kbd>ctrl+t</kbd>: Launch git difftool
<kbd>@</kbd>: 打开命令日志菜单
<kbd>}</kbd>: 扩大差异视图中显示的上下文范围
<kbd>{</kbd>: 缩小差异视图中显示的上下文范围
Expand Down
2 changes: 2 additions & 0 deletions pkg/config/user_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ type KeybindingUniversalConfig struct {
FilteringMenu string `yaml:"filteringMenu"`
DiffingMenu string `yaml:"diffingMenu"`
DiffingMenuAlt string `yaml:"diffingMenu-alt"`
DiffTool string `yaml:"difftool"`
CopyToClipboard string `yaml:"copyToClipboard"`
OpenRecentRepos string `yaml:"openRecentRepos"`
SubmitEditorText string `yaml:"submitEditorText"`
Expand Down Expand Up @@ -473,6 +474,7 @@ func GetDefaultConfig() *UserConfig {
FilteringMenu: "<c-s>",
DiffingMenu: "W",
DiffingMenuAlt: "<c-e>",
DiffTool: "<c-t>",
CopyToClipboard: "<c-o>",
SubmitEditorText: "<enter>",
AppendNewline: "<a-enter>",
Expand Down
33 changes: 33 additions & 0 deletions pkg/gui/diffing.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"strings"

"github.com/jesseduffield/lazygit/pkg/commands/oscommands"
"github.com/jesseduffield/lazygit/pkg/gui/context"
"github.com/jesseduffield/lazygit/pkg/gui/modes/diffing"
"github.com/jesseduffield/lazygit/pkg/gui/types"
Expand Down Expand Up @@ -159,3 +160,35 @@ func (gui *Gui) handleCreateDiffingMenuPanel() error {

return gui.c.Menu(types.CreateMenuOptions{Title: gui.c.Tr.DiffingMenuTitle, Items: menuItems})
}

func (gui *Gui) handleLaunchDiffTool() error {
gui.c.LogAction("Launch DiffTool")

cmdStr := "git difftool --submodule "

file := gui.currentlySelectedFilename()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
file := gui.currentlySelectedFilename()
file := gui.currentlySelectedFilename()
if file == "" {
file = gui.getSelectedPath()
}

for Staged/Unstaged Changes panel

if file == "" || oscommands.FileType(file) == "directory" {
cmdStr += "-d "
} else {
cmdStr += "-y "
}

if gui.State.Modes.Diffing.Active() {
cmdStr += gui.diffStr()
} else {
diffTerm := gui.currentDiffTerminal()
if diffTerm != "" {
cmdStr += fmt.Sprintf(" %s^ %s", diffTerm, diffTerm)
}
}

if file != "" {
cmdStr += " -- " + file
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
cmdStr += " -- " + file
cmdStr += " -- " + gui.os.Quote(file)

}

gui.c.LogCommand(cmdStr, true)

osCmd := gui.os.Cmd.New(cmdStr)

return osCmd.GetCmd().Start()
}
6 changes: 6 additions & 0 deletions pkg/gui/keybindings.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,12 @@ func (self *Gui) GetInitialKeybindings() ([]*types.Binding, []*gocui.ViewMouseBi
Description: self.c.Tr.LcOpenDiffingMenu,
OpensMenu: true,
},
{
ViewName: "",
Key: opts.GetKey(opts.Config.Universal.DiffTool),
Handler: self.handleLaunchDiffTool,
Description: self.c.Tr.LcLaunchDiffTool,
},
{
ViewName: "",
Key: opts.GetKey(opts.Config.Universal.ExtrasMenu),
Expand Down
2 changes: 2 additions & 0 deletions pkg/i18n/english.go
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,7 @@ type TranslationSet struct {
DiffingMenuTitle string
LcSwapDiff string
LcOpenDiffingMenu string
LcLaunchDiffTool string
LcOpenExtrasMenu string
LcShowingGitDiff string
LcCommitDiff string
Expand Down Expand Up @@ -1027,6 +1028,7 @@ func EnglishTranslationSet() TranslationSet {
DiffingMenuTitle: "Diffing",
LcSwapDiff: "reverse diff direction",
LcOpenDiffingMenu: "open diff menu",
LcLaunchDiffTool: "Launch git difftool",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lc in LcSomeTitle actually denotes lowercase, could you change it to launch git difftool then?

// the actual view is the extras view which I intend to give more tabs in future but for now we'll only mention the command log part
LcOpenExtrasMenu: "open command log menu",
LcShowingGitDiff: "showing output for:",
Expand Down