diff --git a/docs/keybindings/Keybindings_en.md b/docs/keybindings/Keybindings_en.md index b5dc93898..f7aaa46c8 100644 --- a/docs/keybindings/Keybindings_en.md +++ b/docs/keybindings/Keybindings_en.md @@ -52,6 +52,7 @@ _Legend: `` means ctrl+b, `` means alt+b, `B` means shift+b_ d: Discard this commit's changes to this file o: Open file e: Edit file + <c-t>: Open external diff tool (git difftool) <space>: Toggle file included in patch a: Toggle all files included in patch <enter>: Enter file to add selected lines to the patch (or toggle directory collapsed) @@ -98,6 +99,7 @@ _Legend: `` means ctrl+b, `` means alt+b, `B` means shift+b_ g: View reset options c: Copy commit (cherry-pick) C: Copy commit range (cherry-pick) + <c-t>: Open external diff tool (git difftool) <enter>: View selected item's files /: Search the current view by text @@ -132,6 +134,7 @@ _Legend: `` means ctrl+b, `` means alt+b, `B` means shift+b_ g: View upstream reset options D: View reset options `: Toggle file tree view + <c-t>: Open external diff tool (git difftool) M: Open external merge tool (git mergetool) f: Fetch /: Search the current view by text @@ -245,6 +248,7 @@ _Legend: `` means ctrl+b, `` means alt+b, `B` means shift+b_ c: Copy commit (cherry-pick) C: Copy commit range (cherry-pick) <c-r>: Reset cherry-picked (copied) commits selection + <c-t>: Open external diff tool (git difftool) <enter>: View commits /: Filter the current view by text @@ -312,6 +316,7 @@ _Legend: `` means ctrl+b, `` means alt+b, `B` means shift+b_ c: Copy commit (cherry-pick) C: Copy commit range (cherry-pick) <c-r>: Reset cherry-picked (copied) commits selection + <c-t>: Open external diff tool (git difftool) <enter>: View selected item's files /: Search the current view by text diff --git a/docs/keybindings/Keybindings_ja.md b/docs/keybindings/Keybindings_ja.md index 3b7ef6991..a5a54b872 100644 --- a/docs/keybindings/Keybindings_ja.md +++ b/docs/keybindings/Keybindings_ja.md @@ -70,6 +70,7 @@ _Legend: `` means ctrl+b, `` means alt+b, `B` means shift+b_ c: コミットをコピー (cherry-pick) C: コミットを範囲コピー (cherry-pick) <c-r>: Reset cherry-picked (copied) commits selection + <c-t>: Open external diff tool (git difftool) <enter>: View selected item's files /: 検索を開始 @@ -117,6 +118,7 @@ _Legend: `` means ctrl+b, `` means alt+b, `B` means shift+b_ g: View reset options c: コミットをコピー (cherry-pick) C: コミットを範囲コピー (cherry-pick) + <c-t>: Open external diff tool (git difftool) <enter>: View selected item's files /: 検索を開始 @@ -129,6 +131,7 @@ _Legend: `` means ctrl+b, `` means alt+b, `B` means shift+b_ d: Discard this commit's changes to this file o: ファイルを開く e: ファイルを編集 + <c-t>: Open external diff tool (git difftool) <space>: Toggle file included in patch a: Toggle all files included in patch <enter>: Enter file to add selected lines to the patch (or toggle directory collapsed) @@ -204,6 +207,7 @@ _Legend: `` means ctrl+b, `` means alt+b, `B` means shift+b_ g: View upstream reset options D: View reset options `: ファイルツリーの表示を切り替え + <c-t>: Open external diff tool (git difftool) M: Git mergetoolを開く f: Fetch /: 検索を開始 @@ -344,6 +348,7 @@ _Legend: `` means ctrl+b, `` means alt+b, `B` means shift+b_ c: コミットをコピー (cherry-pick) C: コミットを範囲コピー (cherry-pick) <c-r>: Reset cherry-picked (copied) commits selection + <c-t>: Open external diff tool (git difftool) <enter>: コミットを閲覧 /: Filter the current view by text diff --git a/docs/keybindings/Keybindings_ko.md b/docs/keybindings/Keybindings_ko.md index 02b5db76e..fc7291c4b 100644 --- a/docs/keybindings/Keybindings_ko.md +++ b/docs/keybindings/Keybindings_ko.md @@ -57,6 +57,7 @@ _Legend: `` means ctrl+b, `` means alt+b, `B` means shift+b_ c: 커밋을 복사 (cherry-pick) C: 커밋을 범위로 복사 (cherry-pick) <c-r>: Reset cherry-picked (copied) commits selection + <c-t>: Open external diff tool (git difftool) <enter>: 커밋 보기 /: Filter the current view by text @@ -87,6 +88,7 @@ _Legend: `` means ctrl+b, `` means alt+b, `B` means shift+b_ c: 커밋을 복사 (cherry-pick) C: 커밋을 범위로 복사 (cherry-pick) <c-r>: Reset cherry-picked (copied) commits selection + <c-t>: Open external diff tool (git difftool) <enter>: View selected item's files /: 검색 시작 @@ -281,6 +283,7 @@ _Legend: `` means ctrl+b, `` means alt+b, `B` means shift+b_ g: View reset options c: 커밋을 복사 (cherry-pick) C: 커밋을 범위로 복사 (cherry-pick) + <c-t>: Open external diff tool (git difftool) <enter>: View selected item's files /: 검색 시작 @@ -293,6 +296,7 @@ _Legend: `` means ctrl+b, `` means alt+b, `B` means shift+b_ d: Discard this commit's changes to this file o: 파일 닫기 e: 파일 편집 + <c-t>: Open external diff tool (git difftool) <space>: Toggle file included in patch a: Toggle all files included in patch <enter>: Enter file to add selected lines to the patch (or toggle directory collapsed) @@ -343,6 +347,7 @@ _Legend: `` means ctrl+b, `` means alt+b, `B` means shift+b_ g: View upstream reset options D: View reset options `: 파일 트리뷰로 전환 + <c-t>: Open external diff tool (git difftool) M: Git mergetool를 열기 f: Fetch /: 검색 시작 diff --git a/docs/keybindings/Keybindings_nl.md b/docs/keybindings/Keybindings_nl.md index e1bddf929..c2d81a06d 100644 --- a/docs/keybindings/Keybindings_nl.md +++ b/docs/keybindings/Keybindings_nl.md @@ -67,6 +67,7 @@ _Legend: `` means ctrl+b, `` means alt+b, `B` means shift+b_ g: Bekijk upstream reset opties D: Bekijk reset opties `: Toggle bestandsboom weergave + <c-t>: Open external diff tool (git difftool) M: Open external merge tool (git mergetool) f: Fetch /: Start met zoeken @@ -120,6 +121,7 @@ _Legend: `` means ctrl+b, `` means alt+b, `B` means shift+b_ d: Uitsluit deze commit zijn veranderingen aan dit bestand o: Open bestand e: Verander bestand + <c-t>: Open external diff tool (git difftool) <space>: Toggle bestand inbegrepen in patch a: Toggle all files included in patch <enter>: Enter bestand om geselecteerde regels toe te voegen aan de patch @@ -159,6 +161,7 @@ _Legend: `` means ctrl+b, `` means alt+b, `B` means shift+b_ g: Bekijk reset opties c: Kopieer commit (cherry-pick) C: Kopieer commit reeks (cherry-pick) + <c-t>: Open external diff tool (git difftool) <enter>: Bekijk gecommite bestanden /: Start met zoeken @@ -223,6 +226,7 @@ _Legend: `` means ctrl+b, `` means alt+b, `B` means shift+b_ c: Kopieer commit (cherry-pick) C: Kopieer commit reeks (cherry-pick) <c-r>: Reset cherry-picked (gekopieerde) commits selectie + <c-t>: Open external diff tool (git difftool) <enter>: Bekijk commits /: Filter the current view by text @@ -312,6 +316,7 @@ _Legend: `` means ctrl+b, `` means alt+b, `B` means shift+b_ c: Kopieer commit (cherry-pick) C: Kopieer commit reeks (cherry-pick) <c-r>: Reset cherry-picked (gekopieerde) commits selectie + <c-t>: Open external diff tool (git difftool) <enter>: Bekijk gecommite bestanden /: Start met zoeken diff --git a/docs/keybindings/Keybindings_pl.md b/docs/keybindings/Keybindings_pl.md index f9eb05e09..2136a5cdf 100644 --- a/docs/keybindings/Keybindings_pl.md +++ b/docs/keybindings/Keybindings_pl.md @@ -83,6 +83,7 @@ _Legend: `` means ctrl+b, `` means alt+b, `B` means shift+b_ g: Wyświetl opcje resetu c: Kopiuj commit (przebieranie) C: Kopiuj zakres commitów (przebieranie) + <c-t>: Open external diff tool (git difftool) <enter>: Przeglądaj pliki commita /: Search the current view by text @@ -167,6 +168,7 @@ _Legend: `` means ctrl+b, `` means alt+b, `B` means shift+b_ g: View upstream reset options D: Wyświetl opcje resetu `: Toggle file tree view + <c-t>: Open external diff tool (git difftool) M: Open external merge tool (git mergetool) f: Pobierz /: Search the current view by text @@ -180,6 +182,7 @@ _Legend: `` means ctrl+b, `` means alt+b, `B` means shift+b_ d: Porzuć zmiany commita dla tego pliku o: Otwórz plik e: Edytuj plik + <c-t>: Open external diff tool (git difftool) <space>: Toggle file included in patch a: Toggle all files included in patch <enter>: Enter file to add selected lines to the patch (or toggle directory collapsed) @@ -222,6 +225,7 @@ _Legend: `` means ctrl+b, `` means alt+b, `B` means shift+b_ c: Kopiuj commit (przebieranie) C: Kopiuj zakres commitów (przebieranie) <c-r>: Reset cherry-picked (copied) commits selection + <c-t>: Open external diff tool (git difftool) <enter>: View commits /: Filter the current view by text @@ -305,6 +309,7 @@ _Legend: `` means ctrl+b, `` means alt+b, `B` means shift+b_ c: Kopiuj commit (przebieranie) C: Kopiuj zakres commitów (przebieranie) <c-r>: Reset cherry-picked (copied) commits selection + <c-t>: Open external diff tool (git difftool) <enter>: Przeglądaj pliki commita /: Search the current view by text diff --git a/docs/keybindings/Keybindings_ru.md b/docs/keybindings/Keybindings_ru.md index f0a1fd4e2..ab82515ad 100644 --- a/docs/keybindings/Keybindings_ru.md +++ b/docs/keybindings/Keybindings_ru.md @@ -129,6 +129,7 @@ _Связки клавиш_ c: Скопировать отобранные коммит (cherry-pick) C: Скопировать несколько отобранных коммитов (cherry-pick) <c-r>: Сбросить отобранную (скопированную | cherry-picked) выборку коммитов + <c-t>: Open external diff tool (git difftool) <enter>: Просмотреть коммиты /: Filter the current view by text @@ -165,6 +166,7 @@ _Связки клавиш_ g: Просмотреть параметры сброса c: Скопировать отобранные коммит (cherry-pick) C: Скопировать несколько отобранных коммитов (cherry-pick) + <c-t>: Open external diff tool (git difftool) <enter>: Просмотреть файлы выбранного элемента /: Найти @@ -223,6 +225,7 @@ _Связки клавиш_ c: Скопировать отобранные коммит (cherry-pick) C: Скопировать несколько отобранных коммитов (cherry-pick) <c-r>: Сбросить отобранную (скопированную | cherry-picked) выборку коммитов + <c-t>: Open external diff tool (git difftool) <enter>: Просмотреть файлы выбранного элемента /: Найти @@ -257,6 +260,7 @@ _Связки клавиш_ d: Отменить изменения коммита в этом файле o: Открыть файл e: Редактировать файл + <c-t>: Open external diff tool (git difftool) <space>: Переключить файлы включённые в патч a: Переключить все файлы, включённые в патч <enter>: Введите файл, чтобы добавить выбранные строки в патч (или свернуть каталог переключения) @@ -337,6 +341,7 @@ _Связки клавиш_ g: Просмотреть параметры сброса upstream-ветки D: Просмотреть параметры сброса `: Переключить вид дерева файлов + <c-t>: Open external diff tool (git difftool) M: Открыть внешний инструмент слияния (git mergetool) f: Получить изменения /: Найти diff --git a/docs/keybindings/Keybindings_zh-CN.md b/docs/keybindings/Keybindings_zh-CN.md index 9b0152851..49bce5ece 100644 --- a/docs/keybindings/Keybindings_zh-CN.md +++ b/docs/keybindings/Keybindings_zh-CN.md @@ -57,6 +57,7 @@ _Legend: `` means ctrl+b, `` means alt+b, `B` means shift+b_ c: 复制提交(拣选) C: 复制提交范围(拣选) <c-r>: 重置已拣选(复制)的提交 + <c-t>: Open external diff tool (git difftool) <enter>: 查看提交 /: Filter the current view by text @@ -111,6 +112,7 @@ _Legend: `` means ctrl+b, `` means alt+b, `B` means shift+b_ c: 复制提交(拣选) C: 复制提交范围(拣选) <c-r>: 重置已拣选(复制)的提交 + <c-t>: Open external diff tool (git difftool) <enter>: 查看提交的文件 /: 开始搜索 @@ -162,6 +164,7 @@ _Legend: `` means ctrl+b, `` means alt+b, `B` means shift+b_ g: 查看重置选项 c: 复制提交(拣选) C: 复制提交范围(拣选) + <c-t>: Open external diff tool (git difftool) <enter>: 查看提交的文件 /: 开始搜索 @@ -174,6 +177,7 @@ _Legend: `` means ctrl+b, `` means alt+b, `B` means shift+b_ d: 放弃对此文件的提交更改 o: 打开文件 e: 编辑文件 + <c-t>: Open external diff tool (git difftool) <space>: 补丁中包含的切换文件 a: Toggle all files included in patch <enter>: 输入文件以将所选行添加到补丁中(或切换目录折叠) @@ -211,6 +215,7 @@ _Legend: `` means ctrl+b, `` means alt+b, `B` means shift+b_ g: 查看上游重置选项 D: 查看重置选项 `: 切换文件树视图 + <c-t>: Open external diff tool (git difftool) M: 打开外部合并工具 (git mergetool) f: 抓取 /: 开始搜索 diff --git a/docs/keybindings/Keybindings_zh-TW.md b/docs/keybindings/Keybindings_zh-TW.md index 866525581..201f79555 100644 --- a/docs/keybindings/Keybindings_zh-TW.md +++ b/docs/keybindings/Keybindings_zh-TW.md @@ -57,6 +57,7 @@ _說明:`` 表示 Ctrl+B、`` 表示 Alt+B,`B`表示 Shift+B_ c: 複製提交 (揀選) C: 複製提交範圍 (揀選) <c-r>: 重設選定的揀選 (複製) 提交 + <c-t>: Open external diff tool (git difftool) <enter>: 檢視提交 /: Filter the current view by text @@ -154,6 +155,7 @@ _說明:`` 表示 Ctrl+B、`` 表示 Alt+B,`B`表示 Shift+B_ c: 複製提交 (揀選) C: 複製提交範圍 (揀選) <c-r>: 重設選定的揀選 (複製) 提交 + <c-t>: Open external diff tool (git difftool) <enter>: 檢視所選項目的檔案 /: 開始搜尋 @@ -205,6 +207,7 @@ _說明:`` 表示 Ctrl+B、`` 表示 Alt+B,`B`表示 Shift+B_ g: 檢視重設選項 c: 複製提交 (揀選) C: 複製提交範圍 (揀選) + <c-t>: Open external diff tool (git difftool) <enter>: 檢視所選項目的檔案 /: 開始搜尋 @@ -224,6 +227,7 @@ _說明:`` 表示 Ctrl+B、`` 表示 Alt+B,`B`表示 Shift+B_ d: 捨棄此提交對此檔案的更改 o: 開啟檔案 e: 編輯檔案 + <c-t>: Open external diff tool (git difftool) <space>: 切換檔案是否包含在補丁中 a: 切換所有檔案是否包含在補丁中 <enter>: 輸入檔案以將選定的行添加至補丁(或切換目錄折疊) @@ -306,6 +310,7 @@ _說明:`` 表示 Ctrl+B、`` 表示 Alt+B,`B`表示 Shift+B_ g: 檢視上游重設選項 D: 檢視重設選項 `: 切換檔案樹狀視圖 + <c-t>: Open external diff tool (git difftool) M: 開啟外部合併工具 (git mergetool) f: 擷取 /: 開始搜尋 diff --git a/pkg/commands/git_commands/diff.go b/pkg/commands/git_commands/diff.go index 1e5f98244..41e71e941 100644 --- a/pkg/commands/git_commands/diff.go +++ b/pkg/commands/git_commands/diff.go @@ -40,3 +40,41 @@ func (self *DiffCommands) GetAllDiff(staged bool) (string, error) { ToArgv(), ).RunWithOutput() } + +type DiffToolCmdOptions struct { + // The path to show a diff for. Pass "." for the entire repo. + Filepath string + + // The commit against which to show the diff. Leave empty to show a diff of + // the working copy. + FromCommit string + + // The commit to diff against FromCommit. Leave empty to diff the working + // copy against FromCommit. Leave both FromCommit and ToCommit empty to show + // the diff of the unstaged working copy changes against the index if Staged + // is false, or the staged changes against HEAD if Staged is true. + ToCommit string + + // Whether to reverse the left and right sides of the diff. + Reverse bool + + // Whether the given Filepath is a directory. We'll pass --dir-diff to + // git-difftool in that case. + IsDirectory bool + + // Whether to show the staged or the unstaged changes. Must be false if both + // FromCommit and ToCommit are non-empty. + Staged bool +} + +func (self *DiffCommands) OpenDiffToolCmdObj(opts DiffToolCmdOptions) oscommands.ICmdObj { + return self.cmd.New(NewGitCmd("difftool"). + Arg("--no-prompt"). + ArgIf(opts.IsDirectory, "--dir-diff"). + ArgIf(opts.Staged, "--cached"). + ArgIf(opts.FromCommit != "", opts.FromCommit). + ArgIf(opts.ToCommit != "", opts.ToCommit). + ArgIf(opts.Reverse, "-R"). + Arg("--", opts.Filepath). + ToArgv()) +} diff --git a/pkg/commands/git_commands/working_tree.go b/pkg/commands/git_commands/working_tree.go index 7921cd26f..9630e2870 100644 --- a/pkg/commands/git_commands/working_tree.go +++ b/pkg/commands/git_commands/working_tree.go @@ -31,10 +31,6 @@ func (self *WorkingTreeCommands) OpenMergeToolCmdObj() oscommands.ICmdObj { return self.cmd.New(NewGitCmd("mergetool").ToArgv()) } -func (self *WorkingTreeCommands) OpenMergeTool() error { - return self.OpenMergeToolCmdObj().Run() -} - // StageFile stages a file func (self *WorkingTreeCommands) StageFile(path string) error { return self.StageFiles([]string{path}) diff --git a/pkg/config/user_config.go b/pkg/config/user_config.go index 749b41822..2392d49cf 100644 --- a/pkg/config/user_config.go +++ b/pkg/config/user_config.go @@ -347,6 +347,7 @@ type KeybindingUniversalConfig struct { ToggleWhitespaceInDiffView string `yaml:"toggleWhitespaceInDiffView"` IncreaseContextInDiffView string `yaml:"increaseContextInDiffView"` DecreaseContextInDiffView string `yaml:"decreaseContextInDiffView"` + OpenDiffTool string `yaml:"openDiffTool"` } type KeybindingStatusConfig struct { @@ -743,6 +744,7 @@ func GetDefaultConfig() *UserConfig { ToggleWhitespaceInDiffView: "", IncreaseContextInDiffView: "}", DecreaseContextInDiffView: "{", + OpenDiffTool: "", }, Status: KeybindingStatusConfig{ CheckForUpdate: "u", diff --git a/pkg/gui/controllers/basic_commits_controller.go b/pkg/gui/controllers/basic_commits_controller.go index 0e98d7b4e..551349466 100644 --- a/pkg/gui/controllers/basic_commits_controller.go +++ b/pkg/gui/controllers/basic_commits_controller.go @@ -3,6 +3,7 @@ package controllers import ( "fmt" + "github.com/jesseduffield/lazygit/pkg/commands/git_commands" "github.com/jesseduffield/lazygit/pkg/commands/models" "github.com/jesseduffield/lazygit/pkg/gui/types" ) @@ -76,6 +77,11 @@ func (self *BasicCommitsController) GetKeybindings(opts types.KeybindingsOpts) [ Handler: self.c.Helpers().CherryPick.Reset, Description: self.c.Tr.ResetCherryPick, }, + { + Key: opts.GetKey(opts.Config.Universal.OpenDiffTool), + Handler: self.checkSelected(self.openDiffTool), + Description: self.c.Tr.OpenDiffTool, + }, } return bindings @@ -272,3 +278,18 @@ func (self *BasicCommitsController) copy(commit *models.Commit) error { func (self *BasicCommitsController) copyRange(*models.Commit) error { return self.c.Helpers().CherryPick.CopyRange(self.context.GetSelectedLineIdx(), self.context.GetCommits(), self.context) } + +func (self *BasicCommitsController) openDiffTool(commit *models.Commit) error { + to := commit.RefName() + from, reverse := self.c.Modes().Diffing.GetFromAndReverseArgsForDiff(commit.ParentRefName()) + _, err := self.c.RunSubprocess(self.c.Git().Diff.OpenDiffToolCmdObj( + git_commands.DiffToolCmdOptions{ + Filepath: ".", + FromCommit: from, + ToCommit: to, + Reverse: reverse, + IsDirectory: true, + Staged: false, + })) + return err +} diff --git a/pkg/gui/controllers/commits_files_controller.go b/pkg/gui/controllers/commits_files_controller.go index 3730a0965..5b3097363 100644 --- a/pkg/gui/controllers/commits_files_controller.go +++ b/pkg/gui/controllers/commits_files_controller.go @@ -2,6 +2,7 @@ package controllers import ( "github.com/jesseduffield/gocui" + "github.com/jesseduffield/lazygit/pkg/commands/git_commands" "github.com/jesseduffield/lazygit/pkg/commands/models" "github.com/jesseduffield/lazygit/pkg/commands/patch" "github.com/jesseduffield/lazygit/pkg/gui/context" @@ -47,6 +48,11 @@ func (self *CommitFilesController) GetKeybindings(opts types.KeybindingsOpts) [] Handler: self.checkSelected(self.edit), Description: self.c.Tr.EditFile, }, + { + Key: opts.GetKey(opts.Config.Universal.OpenDiffTool), + Handler: self.checkSelected(self.openDiffTool), + Description: self.c.Tr.OpenDiffTool, + }, { Key: opts.GetKey(opts.Config.Universal.Select), Handler: self.checkSelected(self.toggleForPatch), @@ -201,6 +207,22 @@ func (self *CommitFilesController) edit(node *filetree.CommitFileNode) error { return self.c.Helpers().Files.EditFile(node.GetPath()) } +func (self *CommitFilesController) openDiffTool(node *filetree.CommitFileNode) error { + ref := self.context().GetRef() + to := ref.RefName() + from, reverse := self.c.Modes().Diffing.GetFromAndReverseArgsForDiff(ref.ParentRefName()) + _, err := self.c.RunSubprocess(self.c.Git().Diff.OpenDiffToolCmdObj( + git_commands.DiffToolCmdOptions{ + Filepath: node.GetPath(), + FromCommit: from, + ToCommit: to, + Reverse: reverse, + IsDirectory: !node.IsFile(), + Staged: false, + })) + return err +} + func (self *CommitFilesController) toggleForPatch(node *filetree.CommitFileNode) error { toggle := func() error { return self.c.WithWaitingStatus(self.c.Tr.UpdatingPatch, func(gocui.Task) error { diff --git a/pkg/gui/controllers/files_controller.go b/pkg/gui/controllers/files_controller.go index 733487d5a..0db509ca3 100644 --- a/pkg/gui/controllers/files_controller.go +++ b/pkg/gui/controllers/files_controller.go @@ -4,6 +4,7 @@ import ( "strings" "github.com/jesseduffield/gocui" + "github.com/jesseduffield/lazygit/pkg/commands/git_commands" "github.com/jesseduffield/lazygit/pkg/commands/models" "github.com/jesseduffield/lazygit/pkg/gui/context" "github.com/jesseduffield/lazygit/pkg/gui/filetree" @@ -122,6 +123,11 @@ func (self *FilesController) GetKeybindings(opts types.KeybindingsOpts) []*types Handler: self.toggleTreeView, Description: self.c.Tr.ToggleTreeView, }, + { + Key: opts.GetKey(opts.Config.Universal.OpenDiffTool), + Handler: self.checkSelectedFileNode(self.openDiffTool), + Description: self.c.Tr.OpenDiffTool, + }, { Key: opts.GetKey(opts.Config.Files.OpenMergeTool), Handler: self.c.Helpers().WorkingTree.OpenMergeTool, @@ -684,6 +690,26 @@ func (self *FilesController) Open() error { return self.c.Helpers().Files.OpenFile(node.GetPath()) } +func (self *FilesController) openDiffTool(node *filetree.FileNode) error { + fromCommit := "" + reverse := false + if self.c.Modes().Diffing.Active() { + fromCommit = self.c.Modes().Diffing.Ref + reverse = self.c.Modes().Diffing.Reverse + } + return self.c.RunSubprocessAndRefresh( + self.c.Git().Diff.OpenDiffToolCmdObj( + git_commands.DiffToolCmdOptions{ + Filepath: node.Path, + FromCommit: fromCommit, + ToCommit: "", + Reverse: reverse, + IsDirectory: !node.IsFile(), + Staged: !node.GetHasUnstagedChanges(), + }), + ) +} + func (self *FilesController) switchToMerge() error { file := self.getSelectedFile() if file == nil { diff --git a/pkg/i18n/english.go b/pkg/i18n/english.go index 06c66d0a6..34df4aba1 100644 --- a/pkg/i18n/english.go +++ b/pkg/i18n/english.go @@ -46,6 +46,7 @@ type TranslationSet struct { ToggleStaged string ToggleStagedAll string ToggleTreeView string + OpenDiffTool string OpenMergeTool string Refresh string Push string @@ -782,6 +783,7 @@ type Actions struct { Undo string Redo string CopyPullRequestURL string + OpenDiffTool string OpenMergeTool string OpenCommitInBrowser string OpenPullRequest string @@ -862,6 +864,7 @@ func EnglishTranslationSet() TranslationSet { ToggleStaged: "Toggle staged", ToggleStagedAll: "Stage/unstage all", ToggleTreeView: "Toggle file tree view", + OpenDiffTool: "Open external diff tool (git difftool)", OpenMergeTool: "Open external merge tool (git mergetool)", Refresh: "Refresh", Push: "Push", @@ -1558,6 +1561,7 @@ func EnglishTranslationSet() TranslationSet { Undo: "Undo", Redo: "Redo", CopyPullRequestURL: "Copy pull request URL", + OpenDiffTool: "Open diff tool", OpenMergeTool: "Open merge tool", OpenCommitInBrowser: "Open commit in browser", OpenPullRequest: "Open pull request in browser", diff --git a/schema/config.json b/schema/config.json index 54f6d6961..45976cbb9 100644 --- a/schema/config.json +++ b/schema/config.json @@ -864,6 +864,10 @@ "decreaseContextInDiffView": { "type": "string", "default": "{" + }, + "openDiffTool": { + "type": "string", + "default": "\u003cc-t\u003e" } }, "additionalProperties": false,