From 2335772db6b3027b06faf79a44983a03e05655af Mon Sep 17 00:00:00 2001 From: "T." <3098462+part22@users.noreply.github.com> Date: Wed, 26 Jun 2024 12:02:37 -0400 Subject: [PATCH] Make opening git difftool more consistent The default shortcut to open git difftool (ctrl+t) is not available on the "Local Branches" window. It is available when selecting a commit from a local branch, a remote branch, or a tag from the "Local Branches" window. This is inconsistent since branches or tags are also commits, the shortcut should also work on them directly. This commit remedies this inconsistency by allowing the use of the shortcut directly on a branch or a tag. The shortcut works both in the "standard" mode and the "diffing" mode. --- docs/keybindings/Keybindings_en.md | 3 +++ docs/keybindings/Keybindings_ja.md | 3 +++ docs/keybindings/Keybindings_ko.md | 3 +++ docs/keybindings/Keybindings_nl.md | 3 +++ docs/keybindings/Keybindings_pl.md | 3 +++ docs/keybindings/Keybindings_ru.md | 3 +++ docs/keybindings/Keybindings_zh-CN.md | 3 +++ docs/keybindings/Keybindings_zh-TW.md | 3 +++ pkg/gui/controllers/branches_controller.go | 8 ++++++++ pkg/gui/controllers/helpers/diff_helper.go | 16 ++++++++++++++++ .../controllers/remote_branches_controller.go | 8 ++++++++ pkg/gui/controllers/tags_controller.go | 8 ++++++++ 12 files changed, 64 insertions(+) diff --git a/docs/keybindings/Keybindings_en.md b/docs/keybindings/Keybindings_en.md index b4e566c9f..73104e994 100644 --- a/docs/keybindings/Keybindings_en.md +++ b/docs/keybindings/Keybindings_en.md @@ -169,6 +169,7 @@ If you would instead like to start an interactive rebase from the selected commi | `` g `` | Reset | | | `` R `` | Rename branch | | | `` u `` | View upstream options | View options relating to the branch's upstream e.g. setting/unsetting the upstream and resetting to the upstream. | +| `` `` | Open external diff tool (git difftool) | | | `` `` | View commits | | | `` w `` | View worktree options | | | `` / `` | Filter the current view by text | | @@ -271,6 +272,7 @@ If you would instead like to start an interactive rebase from the selected commi | `` u `` | Set as upstream | Set the selected remote branch as the upstream of the checked-out branch. | | `` s `` | Sort order | | | `` g `` | Reset | View reset options (soft/mixed/hard) for resetting onto selected item. | +| `` `` | Open external diff tool (git difftool) | | | `` `` | View commits | | | `` w `` | View worktree options | | | `` / `` | Filter the current view by text | | @@ -349,6 +351,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. | +| `` `` | Open external diff tool (git difftool) | | | `` `` | View commits | | | `` w `` | View worktree options | | | `` / `` | Filter the current view by text | | diff --git a/docs/keybindings/Keybindings_ja.md b/docs/keybindings/Keybindings_ja.md index 39741ee7c..9a146261b 100644 --- a/docs/keybindings/Keybindings_ja.md +++ b/docs/keybindings/Keybindings_ja.md @@ -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. | +| `` `` | Open external diff tool (git difftool) | | | `` `` | コミットを閲覧 | | | `` w `` | View worktree options | | | `` / `` | Filter the current view by text | | @@ -239,6 +240,7 @@ If you would instead like to start an interactive rebase from the selected commi | `` g `` | Reset | | | `` R `` | ブランチ名を変更 | | | `` u `` | View upstream options | View options relating to the branch's upstream e.g. setting/unsetting the upstream and resetting to the upstream. | +| `` `` | Open external diff tool (git difftool) | | | `` `` | コミットを閲覧 | | | `` w `` | View worktree options | | | `` / `` | Filter the current view by text | | @@ -335,6 +337,7 @@ If you would instead like to start an interactive rebase from the selected commi | `` u `` | Set as upstream | Set the selected remote branch as the upstream of the checked-out branch. | | `` s `` | 並び替え | | | `` g `` | Reset | View reset options (soft/mixed/hard) for resetting onto selected item. | +| `` `` | Open external diff tool (git difftool) | | | `` `` | コミットを閲覧 | | | `` w `` | View worktree options | | | `` / `` | Filter the current view by text | | diff --git a/docs/keybindings/Keybindings_ko.md b/docs/keybindings/Keybindings_ko.md index 37696b385..289f6931f 100644 --- a/docs/keybindings/Keybindings_ko.md +++ b/docs/keybindings/Keybindings_ko.md @@ -196,6 +196,7 @@ _Legend: `` means ctrl+b, `` means alt+b, `B` means shift+b_ | `` g `` | View reset options | | | `` R `` | 브랜치 이름 변경 | | | `` u `` | View upstream options | View options relating to the branch's upstream e.g. setting/unsetting the upstream and resetting to the upstream. | +| `` `` | Open external diff tool (git difftool) | | | `` `` | 커밋 보기 | | | `` w `` | View worktree options | | | `` / `` | Filter the current view by text | | @@ -248,6 +249,7 @@ _Legend: `` means ctrl+b, `` means alt+b, `B` means shift+b_ | `` u `` | Set as upstream | Set the selected remote branch as the upstream of the checked-out branch. | | `` s `` | Sort order | | | `` g `` | View reset options | View reset options (soft/mixed/hard) for resetting onto selected item. | +| `` `` | Open external diff tool (git difftool) | | | `` `` | 커밋 보기 | | | `` w `` | View worktree options | | | `` / `` | Filter the current view by text | | @@ -322,6 +324,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. | +| `` `` | Open external diff tool (git difftool) | | | `` `` | 커밋 보기 | | | `` w `` | View worktree options | | | `` / `` | Filter the current view by text | | diff --git a/docs/keybindings/Keybindings_nl.md b/docs/keybindings/Keybindings_nl.md index f0f117ab0..03bf0214c 100644 --- a/docs/keybindings/Keybindings_nl.md +++ b/docs/keybindings/Keybindings_nl.md @@ -108,6 +108,7 @@ _Legend: `` means ctrl+b, `` means alt+b, `B` means shift+b_ | `` g `` | Bekijk reset opties | | | `` R `` | Hernoem branch | | | `` u `` | View upstream options | View options relating to the branch's upstream e.g. setting/unsetting the upstream and resetting to the upstream. | +| `` `` | Open external diff tool (git difftool) | | | `` `` | Bekijk commits | | | `` w `` | View worktree options | | | `` / `` | Filter the current view by text | | @@ -249,6 +250,7 @@ If you would instead like to start an interactive rebase from the selected commi | `` u `` | Set as upstream | Stel in als upstream van uitgecheckte branch | | `` s `` | Sort order | | | `` g `` | Bekijk reset opties | View reset options (soft/mixed/hard) for resetting onto selected item. | +| `` `` | Open external diff tool (git difftool) | | | `` `` | Bekijk commits | | | `` w `` | View worktree options | | | `` / `` | Filter the current view by text | | @@ -349,6 +351,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. | +| `` `` | Open external diff tool (git difftool) | | | `` `` | Bekijk commits | | | `` w `` | View worktree options | | | `` / `` | Filter the current view by text | | diff --git a/docs/keybindings/Keybindings_pl.md b/docs/keybindings/Keybindings_pl.md index e41c07e4d..0336419c1 100644 --- a/docs/keybindings/Keybindings_pl.md +++ b/docs/keybindings/Keybindings_pl.md @@ -134,6 +134,7 @@ Jeśli chcesz zamiast tego rozpocząć interaktywny rebase od wybranego commita, | `` g `` | Reset | | | `` R `` | Zmień nazwę gałęzi | | | `` u `` | Pokaż opcje upstream | Pokaż opcje dotyczące upstream gałęzi, np. ustawianie/usuwanie upstream i resetowanie do upstream. | +| `` `` | Otwórz zewnętrzne narzędzie różnic (git difftool) | | | `` `` | Pokaż commity | | | `` w `` | Zobacz opcje drzewa pracy | | | `` / `` | Filtruj bieżący widok po tekście | | @@ -331,6 +332,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. | +| `` `` | Otwórz zewnętrzne narzędzie różnic (git difftool) | | | `` `` | Pokaż commity | | | `` w `` | Zobacz opcje drzewa pracy | | | `` / `` | Filtruj bieżący widok po tekście | | @@ -359,6 +361,7 @@ Jeśli chcesz zamiast tego rozpocząć interaktywny rebase od wybranego commita, | `` u `` | Ustaw jako upstream | Ustaw wybraną gałąź zdalną jako upstream sprawdzonej gałęzi. | | `` s `` | Kolejność sortowania | | | `` g `` | Reset | Wyświetl opcje resetu (miękki/mieszany/twardy) do wybranego elementu. | +| `` `` | Otwórz zewnętrzne narzędzie różnic (git difftool) | | | `` `` | Pokaż commity | | | `` w `` | Zobacz opcje drzewa pracy | | | `` / `` | Filtruj bieżący widok po tekście | | diff --git a/docs/keybindings/Keybindings_ru.md b/docs/keybindings/Keybindings_ru.md index 479df5261..c6a784b72 100644 --- a/docs/keybindings/Keybindings_ru.md +++ b/docs/keybindings/Keybindings_ru.md @@ -196,6 +196,7 @@ If you would instead like to start an interactive rebase from the selected commi | `` g `` | Просмотреть параметры сброса | | | `` R `` | Переименовать ветку | | | `` u `` | View upstream options | View options relating to the branch's upstream e.g. setting/unsetting the upstream and resetting to the upstream. | +| `` `` | Open external diff tool (git difftool) | | | `` `` | Просмотреть коммиты | | | `` w `` | View worktree options | | | `` / `` | Filter the current view by text | | @@ -288,6 +289,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. | +| `` `` | Open external diff tool (git difftool) | | | `` `` | Просмотреть коммиты | | | `` w `` | View worktree options | | | `` / `` | Filter the current view by text | | @@ -305,6 +307,7 @@ If you would instead like to start an interactive rebase from the selected commi | `` u `` | Set as upstream | Установить как upstream-ветку переключённую ветку | | `` s `` | Порядок сортировки | | | `` g `` | Просмотреть параметры сброса | View reset options (soft/mixed/hard) for resetting onto selected item. | +| `` `` | Open external diff tool (git difftool) | | | `` `` | Просмотреть коммиты | | | `` w `` | View worktree options | | | `` / `` | Filter the current view by text | | diff --git a/docs/keybindings/Keybindings_zh-CN.md b/docs/keybindings/Keybindings_zh-CN.md index 3c8e7d3ce..8cb93e519 100644 --- a/docs/keybindings/Keybindings_zh-CN.md +++ b/docs/keybindings/Keybindings_zh-CN.md @@ -98,6 +98,7 @@ _Legend: `` means ctrl+b, `` means alt+b, `B` means shift+b_ | `` g `` | 查看重置选项 | | | `` R `` | 重命名分支 | | | `` u `` | View upstream options | View options relating to the branch's upstream e.g. setting/unsetting the upstream and resetting to the upstream. | +| `` `` | Open external diff tool (git difftool) | | | `` `` | 查看提交 | | | `` w `` | View worktree options | | | `` / `` | Filter the current view by text | | @@ -248,6 +249,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. | +| `` `` | Open external diff tool (git difftool) | | | `` `` | 查看提交 | | | `` w `` | View worktree options | | | `` / `` | Filter the current view by text | | @@ -348,6 +350,7 @@ If you would instead like to start an interactive rebase from the selected commi | `` u `` | Set as upstream | 设置为检出分支的上游 | | `` s `` | Sort order | | | `` g `` | 查看重置选项 | View reset options (soft/mixed/hard) for resetting onto selected item. | +| `` `` | Open external diff tool (git difftool) | | | `` `` | 查看提交 | | | `` w `` | View worktree options | | | `` / `` | Filter the current view by text | | diff --git a/docs/keybindings/Keybindings_zh-TW.md b/docs/keybindings/Keybindings_zh-TW.md index a90334dad..d82e3361d 100644 --- a/docs/keybindings/Keybindings_zh-TW.md +++ b/docs/keybindings/Keybindings_zh-TW.md @@ -271,6 +271,7 @@ If you would instead like to start an interactive rebase from the selected commi | `` g `` | 檢視重設選項 | | | `` R `` | 重新命名分支 | | | `` u `` | 檢視上游設定 | 檢視有關上游分支的設定(例如重設至上游) | +| `` `` | Open external diff tool (git difftool) | | | `` `` | 檢視提交 | | | `` w `` | 檢視工作目錄選項 | | | `` / `` | 搜尋 | | @@ -284,6 +285,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. | +| `` `` | Open external diff tool (git difftool) | | | `` `` | 檢視提交 | | | `` w `` | 檢視工作目錄選項 | | | `` / `` | 搜尋 | | @@ -359,6 +361,7 @@ If you would instead like to start an interactive rebase from the selected commi | `` u `` | Set as upstream | 將此分支設為當前分支之上游 | | `` s `` | Sort order | | | `` g `` | 檢視重設選項 | View reset options (soft/mixed/hard) for resetting onto selected item. | +| `` `` | Open external diff tool (git difftool) | | | `` `` | 檢視提交 | | | `` w `` | 檢視工作目錄選項 | | | `` / `` | 搜尋 | | diff --git a/pkg/gui/controllers/branches_controller.go b/pkg/gui/controllers/branches_controller.go index 9f5ba7f05..f0d0899a5 100644 --- a/pkg/gui/controllers/branches_controller.go +++ b/pkg/gui/controllers/branches_controller.go @@ -159,6 +159,14 @@ func (self *BranchesController) GetKeybindings(opts types.KeybindingsOpts) []*ty OpensMenu: true, DisplayOnScreen: true, }, + { + Key: opts.GetKey(opts.Config.Universal.OpenDiffTool), + Handler: self.withItem(func(selectedBranch *models.Branch) error { + return self.c.Helpers().Diff.OpenDiffToolForRef(selectedBranch) + }), + GetDisabledReason: self.require(self.singleItemSelected()), + Description: self.c.Tr.OpenDiffTool, + }, } } diff --git a/pkg/gui/controllers/helpers/diff_helper.go b/pkg/gui/controllers/helpers/diff_helper.go index bf4b33052..8b5c01cd3 100644 --- a/pkg/gui/controllers/helpers/diff_helper.go +++ b/pkg/gui/controllers/helpers/diff_helper.go @@ -1,6 +1,7 @@ package helpers import ( + "github.com/jesseduffield/lazygit/pkg/commands/git_commands" "github.com/jesseduffield/lazygit/pkg/gui/context" "github.com/jesseduffield/lazygit/pkg/gui/modes/diffing" "github.com/jesseduffield/lazygit/pkg/gui/types" @@ -119,3 +120,18 @@ func (self *DiffHelper) IgnoringWhitespaceSubTitle() string { return "" } + +func (self *DiffHelper) OpenDiffToolForRef(selectedRef types.Ref) error { + to := selectedRef.RefName() + from, reverse := self.c.Modes().Diffing.GetFromAndReverseArgsForDiff("") + _, 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/remote_branches_controller.go b/pkg/gui/controllers/remote_branches_controller.go index d793c6148..c859ef3f6 100644 --- a/pkg/gui/controllers/remote_branches_controller.go +++ b/pkg/gui/controllers/remote_branches_controller.go @@ -94,6 +94,14 @@ func (self *RemoteBranchesController) GetKeybindings(opts types.KeybindingsOpts) Tooltip: self.c.Tr.ResetTooltip, OpensMenu: true, }, + { + Key: opts.GetKey(opts.Config.Universal.OpenDiffTool), + Handler: self.withItem(func(selectedBranch *models.RemoteBranch) error { + return self.c.Helpers().Diff.OpenDiffToolForRef(selectedBranch) + }), + GetDisabledReason: self.require(self.singleItemSelected()), + Description: self.c.Tr.OpenDiffTool, + }, } } diff --git a/pkg/gui/controllers/tags_controller.go b/pkg/gui/controllers/tags_controller.go index d845f192d..623ef7217 100644 --- a/pkg/gui/controllers/tags_controller.go +++ b/pkg/gui/controllers/tags_controller.go @@ -74,6 +74,14 @@ func (self *TagsController) GetKeybindings(opts types.KeybindingsOpts) []*types. DisplayOnScreen: true, OpensMenu: true, }, + { + Key: opts.GetKey(opts.Config.Universal.OpenDiffTool), + Handler: self.withItem(func(selectedTag *models.Tag) error { + return self.c.Helpers().Diff.OpenDiffToolForRef(selectedTag) + }), + GetDisabledReason: self.require(self.singleItemSelected()), + Description: self.c.Tr.OpenDiffTool, + }, } return bindings