diff --git a/docs-master/keybindings/Keybindings_en.md b/docs-master/keybindings/Keybindings_en.md index 63bb3a24c..20bca0c61 100644 --- a/docs-master/keybindings/Keybindings_en.md +++ b/docs-master/keybindings/Keybindings_en.md @@ -234,6 +234,10 @@ _This file is auto-generated. To update, make the changes in the pkg/i18n direct | `` N `` | Go to previous file | | | `` n `` | Go to next file | | | `` `` | Exit back to side panel | | +| `` c `` | Commit | Commit staged changes. | +| `` w `` | Commit changes without pre-commit hook | | +| `` C `` | Commit changes using git editor | | +| `` `` | Find base commit for fixup | Find the commit that your current changes are building upon, for the sake of amending/fixing up the commit. This spares you from having to look through your branch's commits one-by-one to see which commit should be amended/fixed up. See docs: | | `` / `` | Search the current view by text | | ## Main panel (patch building) @@ -349,6 +353,10 @@ _This file is auto-generated. To update, make the changes in the pkg/i18n direct | `` N `` | Go to previous file | | | `` n `` | Go to next file | | | `` `` | Exit back to side panel | | +| `` c `` | Commit | Commit staged changes. | +| `` w `` | Commit changes without pre-commit hook | | +| `` C `` | Commit changes using git editor | | +| `` `` | Find base commit for fixup | Find the commit that your current changes are building upon, for the sake of amending/fixing up the commit. This spares you from having to look through your branch's commits one-by-one to see which commit should be amended/fixed up. See docs: | | `` / `` | Search the current view by text | | ## Stash diff --git a/docs-master/keybindings/Keybindings_ja.md b/docs-master/keybindings/Keybindings_ja.md index 786750b16..6d2767953 100644 --- a/docs-master/keybindings/Keybindings_ja.md +++ b/docs-master/keybindings/Keybindings_ja.md @@ -203,6 +203,10 @@ _This file is auto-generated. To update, make the changes in the pkg/i18n direct | `` N `` | Go to previous file | | | `` n `` | Go to next file | | | `` `` | サイドパネルに戻る | | +| `` c `` | コミット | ステージされた変更をコミットします。 | +| `` w `` | pre-commitフックなしで変更をコミット | | +| `` C `` | Gitエディタを使用して変更をコミット | | +| `` `` | フィックスアップのベースコミットを検索 | 現在の変更が基づいているコミットを見つけて、コミットの修正/フィックスアップを行います。これにより、ブランチのコミットを一つずつ確認して、どのコミットを修正/フィックスアップすべきかを調べる手間が省けます。詳細はドキュメントを参照: | | `` / `` | 現在のビューをテキストで検索 | | ## タグ @@ -326,6 +330,10 @@ _This file is auto-generated. To update, make the changes in the pkg/i18n direct | `` N `` | Go to previous file | | | `` n `` | Go to next file | | | `` `` | サイドパネルに戻る | | +| `` c `` | コミット | ステージされた変更をコミットします。 | +| `` w `` | pre-commitフックなしで変更をコミット | | +| `` C `` | Gitエディタを使用して変更をコミット | | +| `` `` | フィックスアップのベースコミットを検索 | 現在の変更が基づいているコミットを見つけて、コミットの修正/フィックスアップを行います。これにより、ブランチのコミットを一つずつ確認して、どのコミットを修正/フィックスアップすべきかを調べる手間が省けます。詳細はドキュメントを参照: | | `` / `` | 現在のビューをテキストで検索 | | ## メニュー diff --git a/docs-master/keybindings/Keybindings_ko.md b/docs-master/keybindings/Keybindings_ko.md index 3adec5eb8..dab679603 100644 --- a/docs-master/keybindings/Keybindings_ko.md +++ b/docs-master/keybindings/Keybindings_ko.md @@ -95,6 +95,10 @@ _This file is auto-generated. To update, make the changes in the pkg/i18n direct | `` N `` | Go to previous file | | | `` n `` | Go to next file | | | `` `` | Exit back to side panel | | +| `` c `` | 커밋 변경내용 | 스테이징된 변경 사항 커밋. | +| `` w `` | Commit changes without pre-commit hook | | +| `` C `` | Git 편집기를 사용하여 변경 내용을 커밋합니다. | | +| `` `` | Find base commit for fixup | Find the commit that your current changes are building upon, for the sake of amending/fixing up the commit. This spares you from having to look through your branch's commits one-by-one to see which commit should be amended/fixed up. See docs: | | `` / `` | 검색 시작 | | ## Stash @@ -183,6 +187,10 @@ _This file is auto-generated. To update, make the changes in the pkg/i18n direct | `` N `` | Go to previous file | | | `` n `` | Go to next file | | | `` `` | Exit back to side panel | | +| `` c `` | 커밋 변경내용 | 스테이징된 변경 사항 커밋. | +| `` w `` | Commit changes without pre-commit hook | | +| `` C `` | Git 편집기를 사용하여 변경 내용을 커밋합니다. | | +| `` `` | Find base commit for fixup | Find the commit that your current changes are building upon, for the sake of amending/fixing up the commit. This spares you from having to look through your branch's commits one-by-one to see which commit should be amended/fixed up. See docs: | | `` / `` | 검색 시작 | | ## 메인 패널 (Patch Building) diff --git a/docs-master/keybindings/Keybindings_nl.md b/docs-master/keybindings/Keybindings_nl.md index 065a98df2..f336abffa 100644 --- a/docs-master/keybindings/Keybindings_nl.md +++ b/docs-master/keybindings/Keybindings_nl.md @@ -242,6 +242,10 @@ _This file is auto-generated. To update, make the changes in the pkg/i18n direct | `` N `` | Go to previous file | | | `` n `` | Go to next file | | | `` `` | Exit back to side panel | | +| `` c `` | Commit veranderingen | Commit gestagede wijzigingen. | +| `` w `` | Commit veranderingen zonder pre-commit hook | | +| `` C `` | Commit veranderingen met de git editor | | +| `` `` | Find base commit for fixup | Vind de commit waar je huidige wijzigingen bovenop zijn gebouwd met als doel die commit te amenden/fixen. Hierdoor hoef je dit niet met de hand te doen. Zie: | | `` / `` | Start met zoeken | | ## Patch bouwen @@ -327,6 +331,10 @@ _This file is auto-generated. To update, make the changes in the pkg/i18n direct | `` N `` | Go to previous file | | | `` n `` | Go to next file | | | `` `` | Exit back to side panel | | +| `` c `` | Commit veranderingen | Commit gestagede wijzigingen. | +| `` w `` | Commit veranderingen zonder pre-commit hook | | +| `` C `` | Commit veranderingen met de git editor | | +| `` `` | Find base commit for fixup | Vind de commit waar je huidige wijzigingen bovenop zijn gebouwd met als doel die commit te amenden/fixen. Hierdoor hoef je dit niet met de hand te doen. Zie: | | `` / `` | Start met zoeken | | ## Staging diff --git a/docs-master/keybindings/Keybindings_pl.md b/docs-master/keybindings/Keybindings_pl.md index 58d7eeb80..b9f928561 100644 --- a/docs-master/keybindings/Keybindings_pl.md +++ b/docs-master/keybindings/Keybindings_pl.md @@ -110,6 +110,10 @@ _This file is auto-generated. To update, make the changes in the pkg/i18n direct | `` N `` | Go to previous file | | | `` n `` | Go to next file | | | `` `` | Exit back to side panel | | +| `` c `` | Commit | Zatwierdź zmiany zatwierdzone. | +| `` w `` | Zatwierdź zmiany bez hooka pre-commit | | +| `` C `` | Zatwierdź zmiany używając edytora git | | +| `` `` | Znajdź bazowy commit do poprawki | Znajdź commit, na którym opierają się Twoje obecne zmiany, w celu poprawienia/zmiany commita. To pozwala Ci uniknąć przeglądania commitów w Twojej gałęzi jeden po drugim, aby zobaczyć, który commit powinien być poprawiony/zmieniony. Zobacz dokumentację: | | `` / `` | Szukaj w bieżącym widoku po tekście | | ## Drzewa pracy @@ -222,6 +226,10 @@ _This file is auto-generated. To update, make the changes in the pkg/i18n direct | `` N `` | Go to previous file | | | `` n `` | Go to next file | | | `` `` | Exit back to side panel | | +| `` c `` | Commit | Zatwierdź zmiany zatwierdzone. | +| `` w `` | Zatwierdź zmiany bez hooka pre-commit | | +| `` C `` | Zatwierdź zmiany używając edytora git | | +| `` `` | Znajdź bazowy commit do poprawki | Znajdź commit, na którym opierają się Twoje obecne zmiany, w celu poprawienia/zmiany commita. To pozwala Ci uniknąć przeglądania commitów w Twojej gałęzi jeden po drugim, aby zobaczyć, który commit powinien być poprawiony/zmieniony. Zobacz dokumentację: | | `` / `` | Szukaj w bieżącym widoku po tekście | | ## Panel główny (scalanie) diff --git a/docs-master/keybindings/Keybindings_pt.md b/docs-master/keybindings/Keybindings_pt.md index ff80a02db..4e4f954e1 100644 --- a/docs-master/keybindings/Keybindings_pt.md +++ b/docs-master/keybindings/Keybindings_pt.md @@ -246,6 +246,10 @@ _This file is auto-generated. To update, make the changes in the pkg/i18n direct | `` N `` | Go to previous file | | | `` n `` | Go to next file | | | `` `` | Exit back to side panel | | +| `` c `` | Commit | Submeter mudanças em staging | +| `` w `` | Fazer commit de alterações sem pré-commit | | +| `` C `` | Enviar alteração usando um editor Git | | +| `` `` | Encontrar commit da base para corrigir | Encontre o commit em que as suas mudanças atuais estão se baseando, para alterar/consertar o commit. Isso poupa-te você de ter que olhar pelos commits da sua branch um por um para ver qual commit deve ser alterado/consertado
Veja a documentação:
| | `` / `` | Pesquisar na visualização atual por texto | | ## Painel Principal (preparação) @@ -358,6 +362,10 @@ _This file is auto-generated. To update, make the changes in the pkg/i18n direct | `` N `` | Go to previous file | | | `` n `` | Go to next file | | | `` `` | Exit back to side panel | | +| `` c `` | Commit | Submeter mudanças em staging | +| `` w `` | Fazer commit de alterações sem pré-commit | | +| `` C `` | Enviar alteração usando um editor Git | | +| `` `` | Encontrar commit da base para corrigir | Encontre o commit em que as suas mudanças atuais estão se baseando, para alterar/consertar o commit. Isso poupa-te você de ter que olhar pelos commits da sua branch um por um para ver qual commit deve ser alterado/consertado
Veja a documentação:
| | `` / `` | Pesquisar na visualização atual por texto | | ## Stash diff --git a/docs-master/keybindings/Keybindings_ru.md b/docs-master/keybindings/Keybindings_ru.md index 7545311a0..93b252eae 100644 --- a/docs-master/keybindings/Keybindings_ru.md +++ b/docs-master/keybindings/Keybindings_ru.md @@ -85,6 +85,10 @@ _This file is auto-generated. To update, make the changes in the pkg/i18n direct | `` N `` | Go to previous file | | | `` n `` | Go to next file | | | `` `` | Exit back to side panel | | +| `` c `` | Сохранить изменения | Commit staged changes. | +| `` w `` | Закоммитить изменения без предварительного хука коммита | | +| `` C `` | Сохранить изменения с помощью редактора git | | +| `` `` | Find base commit for fixup | Find the commit that your current changes are building upon, for the sake of amending/fixing up the commit. This spares you from having to look through your branch's commits one-by-one to see which commit should be amended/fixed up. See docs: | | `` / `` | Найти | | ## Главная панель (Индексирование) @@ -127,6 +131,10 @@ _This file is auto-generated. To update, make the changes in the pkg/i18n direct | `` N `` | Go to previous file | | | `` n `` | Go to next file | | | `` `` | Exit back to side panel | | +| `` c `` | Сохранить изменения | Commit staged changes. | +| `` w `` | Закоммитить изменения без предварительного хука коммита | | +| `` C `` | Сохранить изменения с помощью редактора git | | +| `` `` | Find base commit for fixup | Find the commit that your current changes are building upon, for the sake of amending/fixing up the commit. This spares you from having to look through your branch's commits one-by-one to see which commit should be amended/fixed up. See docs: | | `` / `` | Найти | | ## Главная панель (Слияние) diff --git a/docs-master/keybindings/Keybindings_zh-CN.md b/docs-master/keybindings/Keybindings_zh-CN.md index a18cd0177..499651f96 100644 --- a/docs-master/keybindings/Keybindings_zh-CN.md +++ b/docs-master/keybindings/Keybindings_zh-CN.md @@ -297,6 +297,10 @@ _This file is auto-generated. To update, make the changes in the pkg/i18n direct | `` N `` | Go to previous file | | | `` n `` | Go to next file | | | `` `` | 退出回到侧边面板 | | +| `` c `` | 提交变更 | 提交暂存文件 | +| `` w `` | 提交变更而无需预先提交钩子 | | +| `` C `` | 使用 Git 编辑器提交变更 | | +| `` `` | 找到用于修复的基准提交 | 找到您当前变更所基于的提交,以便于修正/改进该提交。这样做可以省去您逐一查看分支提交来确定应该修正/改进哪个提交的麻烦。请参阅文档: | | `` / `` | 开始搜索 | | ## 正在合并 @@ -355,6 +359,10 @@ _This file is auto-generated. To update, make the changes in the pkg/i18n direct | `` N `` | Go to previous file | | | `` n `` | Go to next file | | | `` `` | 退出回到侧边面板 | | +| `` c `` | 提交变更 | 提交暂存文件 | +| `` w `` | 提交变更而无需预先提交钩子 | | +| `` C `` | 使用 Git 编辑器提交变更 | | +| `` `` | 找到用于修复的基准提交 | 找到您当前变更所基于的提交,以便于修正/改进该提交。这样做可以省去您逐一查看分支提交来确定应该修正/改进哪个提交的麻烦。请参阅文档: | | `` / `` | 开始搜索 | | ## 状态 diff --git a/docs-master/keybindings/Keybindings_zh-TW.md b/docs-master/keybindings/Keybindings_zh-TW.md index 7edb92940..8d6994350 100644 --- a/docs-master/keybindings/Keybindings_zh-TW.md +++ b/docs-master/keybindings/Keybindings_zh-TW.md @@ -86,6 +86,10 @@ _This file is auto-generated. To update, make the changes in the pkg/i18n direct | `` N `` | Go to previous file | | | `` n `` | Go to next file | | | `` `` | 退出回到側邊面板 | | +| `` c `` | 提交變更 | 提交暫存區變更 | +| `` w `` | 沒有預提交 hook 就提交更改 | | +| `` C `` | 使用 git 編輯器提交變更 | | +| `` `` | 尋找 fixup 的基礎提交 | 找出目前變更所依據的提交,以便 amend/fixup。這樣不必逐一檢視分支中的提交來找出要 amend/fixup 的提交。請見文件: | | `` / `` | 搜尋 | | ## 主面板(合併) @@ -377,6 +381,10 @@ _This file is auto-generated. To update, make the changes in the pkg/i18n direct | `` N `` | Go to previous file | | | `` n `` | Go to next file | | | `` `` | 退出回到側邊面板 | | +| `` c `` | 提交變更 | 提交暫存區變更 | +| `` w `` | 沒有預提交 hook 就提交更改 | | +| `` C `` | 使用 git 編輯器提交變更 | | +| `` `` | 尋找 fixup 的基礎提交 | 找出目前變更所依據的提交,以便 amend/fixup。這樣不必逐一檢視分支中的提交來找出要 amend/fixup 的提交。請見文件: | | `` / `` | 搜尋 | | ## 狀態 diff --git a/pkg/gui/controllers/main_view_controller.go b/pkg/gui/controllers/main_view_controller.go index 2e8874c6b..62953a844 100644 --- a/pkg/gui/controllers/main_view_controller.go +++ b/pkg/gui/controllers/main_view_controller.go @@ -164,6 +164,32 @@ func (self *MainViewController) GetKeybindings(opts types.KeybindingsOpts) []*ty DescriptionFunc: self.diffSelectionDescriptionText(self.c.Tr.RangeSelectDown), GetDisabledReason: self.diffSelectionDisabledReason, }, + { + Keys: opts.GetKeys(opts.Config.Files.CommitChanges), + Handler: self.workingTreeAction(self.c.Helpers().WorkingTree.HandleCommitPress), + Description: self.c.Tr.Commit, + DescriptionFunc: self.workingTreeActionDescription(self.c.Tr.Commit), + Tooltip: self.c.Tr.CommitTooltip, + }, + { + Keys: opts.GetKeys(opts.Config.Files.CommitChangesWithoutHook), + Handler: self.workingTreeAction(self.c.Helpers().WorkingTree.HandleWIPCommitPress), + Description: self.c.Tr.CommitChangesWithoutHook, + DescriptionFunc: self.workingTreeActionDescription(self.c.Tr.CommitChangesWithoutHook), + }, + { + Keys: opts.GetKeys(opts.Config.Files.CommitChangesWithEditor), + Handler: self.workingTreeAction(self.c.Helpers().WorkingTree.HandleCommitEditorPress), + Description: self.c.Tr.CommitChangesWithEditor, + DescriptionFunc: self.workingTreeActionDescription(self.c.Tr.CommitChangesWithEditor), + }, + { + Keys: opts.GetKeys(opts.Config.Files.FindBaseCommitForFixup), + Handler: self.workingTreeAction(self.c.Helpers().FixupHelper.HandleFindBaseCommitForFixupPress), + Description: self.c.Tr.FindBaseCommitForFixup, + DescriptionFunc: self.workingTreeActionDescription(self.c.Tr.FindBaseCommitForFixup), + Tooltip: self.c.Tr.FindBaseCommitForFixupTooltip, + }, {Tag: "navigation", Keys: opts.GetKeys(opts.Config.Universal.PrevPage), Handler: self.handlePrevPage, Description: self.c.Tr.PrevPage}, {Tag: "navigation", Keys: opts.GetKeys(opts.Config.Universal.NextPage), Handler: self.handleNextPage, Description: self.c.Tr.NextPage}, {Tag: "navigation", Keys: opts.GetKeys(opts.Config.Universal.GotoTop), Handler: self.handleGotoTop, Description: self.c.Tr.GotoTop}, @@ -365,6 +391,20 @@ func (self *MainViewController) discardSelection() error { return actions.DiscardSelection(self.context, first, last) } +// workingTreeAction wraps a command that acts on the working tree — committing, finding +// the commit to fix up — so that it only runs while the focused main view is showing the +// working tree's diff. Over a commit's diff the key does nothing, so that browsing +// through history can't commit by accident. The check is per press, since what the main +// view shows changes as the user moves around while the keybindings are registered once. +func (self *MainViewController) workingTreeAction(action func() error) func() error { + return func() error { + if self.diffMainViewType() != types.DiffMainViewTypeStaging { + return nil + } + return action() + } +} + // workingTreeActionDescription gives a command's description only where the command // applies — over the working tree's diff — so that it is listed there and nowhere else. func (self *MainViewController) workingTreeActionDescription(description string) func() string { diff --git a/pkg/integration/tests/main_view/commit_from_main_view.go b/pkg/integration/tests/main_view/commit_from_main_view.go new file mode 100644 index 000000000..fc56ddaf9 --- /dev/null +++ b/pkg/integration/tests/main_view/commit_from_main_view.go @@ -0,0 +1,67 @@ +package main_view + +import ( + "github.com/jesseduffield/lazygit/pkg/config" + . "github.com/jesseduffield/lazygit/pkg/integration/components" +) + +var CommitFromMainView = NewIntegrationTest(NewIntegrationTestArgs{ + Description: "Commit what you staged without leaving the focused main view, but not while looking at a commit's diff", + ExtraCmdArgs: []string{}, + Skip: false, + SetupConfig: func(cfg *config.AppConfig) { + cfg.GetUserConfig().Gui.UseHunkModeInStagingView = false + }, + SetupRepo: func(shell *Shell) { + shell.CreateFileAndAdd("file1", "one\ntwo\nthree\n") + shell.Commit("one") + + shell.UpdateFile("file1", "one\nADDED\ntwo\nthree\n") + }, + Run: func(t *TestDriver, keys config.KeybindingConfig) { + // Committing acts on the working tree, so it is offered over the working tree's + // diff and does nothing over a commit's. + t.Views().Commits(). + Focus(). + Press(keys.Universal.FocusMainView) + + t.Views().Main(). + IsFocused(). + Press(keys.Files.CommitChanges). + // Nothing happened: the commit message panel would have taken the focus. + IsFocused() + + t.Views().Files(). + Focus(). + Press(keys.Universal.FocusMainView) + + t.Views().Main(). + IsFocused(). + SelectedLines( + Contains("+ADDED"), + ). + PressPrimaryAction() + + // Staging it left nothing unstaged, so the diff — and the focus with it — is in + // the pane the staged side has. + t.Views().Secondary(). + IsFocused(). + Press(keys.Files.CommitChanges) + + t.ExpectPopup().CommitMessagePanel(). + Type("staged from the diff"). + Confirm() + + // The commit left the staged side with nothing in it, so the pane it was made + // from is gone and the focus is in the one that is still there. + t.Views().Secondary().IsInvisible() + t.Views().Main(). + IsFocused(). + Content(Contains("No changed files")) + + t.Views().Commits().Lines( + Contains("staged from the diff"), + Contains("one"), + ) + }, +}) diff --git a/pkg/integration/tests/test_list.go b/pkg/integration/tests/test_list.go index 50efa3102..79f42c278 100644 --- a/pkg/integration/tests/test_list.go +++ b/pkg/integration/tests/test_list.go @@ -368,6 +368,7 @@ var tests = []*components.IntegrationTest{ interactive_rebase.SwapWithConflict, interactive_rebase.ViewFilesOfTodoEntries, main_view.ClickSelectsDiffLine, + main_view.CommitFromMainView, main_view.CopyRowsThatAreNoDiffLine, main_view.CopySelectedDiffLines, main_view.DiscardDiffLines,