From 0f2f20b900bd4bb0610bda9ae89890e3ffe1e27d Mon Sep 17 00:00:00 2001 From: Jesse Duffield Date: Sun, 8 Feb 2026 09:04:26 +1100 Subject: [PATCH] Allow discarding lines from patch directly I always press 'd' in the patch building view, expecting that I can do exactly what I can do in the staging view, to find out I need to go space -> ctrl+p -> d and I think it's time to honour the muscle memory and support this convenience keybinding. --- docs-master/keybindings/Keybindings_en.md | 3 +- docs-master/keybindings/Keybindings_ja.md | 3 +- docs-master/keybindings/Keybindings_ko.md | 3 +- docs-master/keybindings/Keybindings_nl.md | 3 +- docs-master/keybindings/Keybindings_pl.md | 3 +- docs-master/keybindings/Keybindings_pt.md | 3 +- docs-master/keybindings/Keybindings_ru.md | 3 +- docs-master/keybindings/Keybindings_zh-CN.md | 3 +- docs-master/keybindings/Keybindings_zh-TW.md | 3 +- .../controllers/patch_building_controller.go | 75 +++++++++++++++++++ pkg/i18n/english.go | 12 +++ .../discard_lines_from_commit.go | 63 ++++++++++++++++ pkg/integration/tests/test_list.go | 1 + 13 files changed, 169 insertions(+), 9 deletions(-) create mode 100644 pkg/integration/tests/patch_building/discard_lines_from_commit.go diff --git a/docs-master/keybindings/Keybindings_en.md b/docs-master/keybindings/Keybindings_en.md index b570e2681..9e2bce45b 100644 --- a/docs-master/keybindings/Keybindings_en.md +++ b/docs-master/keybindings/Keybindings_en.md @@ -60,7 +60,7 @@ _Legend: `` means ctrl+b, `` means alt+b, `B` means shift+b_ | `` `` | Copy path to clipboard | | | `` y `` | Copy to clipboard | | | `` c `` | Checkout | Checkout file. This replaces the file in your working tree with the version from the selected commit. | -| `` d `` | Remove | Discard this commit's changes to this file. This runs an interactive rebase in the background, so you may get a merge conflict if a later commit also changes this file. | +| `` d `` | Discard | Discard this commit's changes to this file. This runs an interactive rebase in the background, so you may get a merge conflict if a later commit also changes this file. | | `` o `` | Open file | Open file in default application. | | `` e `` | Edit | Open file in external editor. | | `` `` | Open external diff tool (git difftool) | | @@ -237,6 +237,7 @@ _Legend: `` means ctrl+b, `` means alt+b, `B` means shift+b_ | `` o `` | Open file | Open file in default application. | | `` e `` | Edit file | Open file in external editor. | | `` `` | Toggle lines in patch | | +| `` d `` | Remove lines from commit | Remove the selected lines from this commit. This runs an interactive rebase in the background, so you may get a merge conflict if a later commit also changes these lines. | | `` `` | Exit custom patch builder | | | `` / `` | Search the current view by text | | diff --git a/docs-master/keybindings/Keybindings_ja.md b/docs-master/keybindings/Keybindings_ja.md index b657aa794..ce9657e4e 100644 --- a/docs-master/keybindings/Keybindings_ja.md +++ b/docs-master/keybindings/Keybindings_ja.md @@ -108,7 +108,7 @@ _凡例:`<c-b>` はctrl+b、`<a-b>` はalt+b、`B` はshift+bを意味 | `` `` | パスをクリップボードにコピー | | | `` y `` | クリップボードにコピー | | | `` c `` | チェックアウト(ブランチの切り替え) | ファイルをチェックアウトします。これにより、作業ツリー内のファイルが選択したコミットのバージョンに置き換えられます。 | -| `` d `` | 削除 | このコミットのこのファイルへの変更を破棄します。これはバックグラウンドで対話的なリベースを実行するため、後のコミットでもこのファイルが変更されている場合、マージコンフリクトが発生する可能性があります。 | +| `` d `` | 破棄 | このコミットのこのファイルへの変更を破棄します。これはバックグラウンドで対話的なリベースを実行するため、後のコミットでもこのファイルが変更されている場合、マージコンフリクトが発生する可能性があります。 | | `` o `` | ファイルを開く | デフォルトのアプリケーションでファイルを開きます。 | | `` e `` | 編集 | 外部エディタでファイルを開きます。 | | `` `` | 外部差分ツールを開く(git difftool) | | @@ -278,6 +278,7 @@ _凡例:`<c-b>` はctrl+b、`<a-b>` はalt+b、`B` はshift+bを意味 | `` o `` | ファイルを開く | デフォルトのアプリケーションでファイルを開きます。 | | `` e `` | ファイルを編集 | 外部エディタでファイルを開きます。 | | `` `` | パッチ内の行を切り替え | | +| `` d `` | Remove lines from commit | Remove the selected lines from this commit. This runs an interactive rebase in the background, so you may get a merge conflict if a later commit also changes these lines. | | `` `` | カスタムパッチビルダーを終了 | | | `` / `` | 現在のビューをテキストで検索 | | diff --git a/docs-master/keybindings/Keybindings_ko.md b/docs-master/keybindings/Keybindings_ko.md index 0860c8571..134c0ae04 100644 --- a/docs-master/keybindings/Keybindings_ko.md +++ b/docs-master/keybindings/Keybindings_ko.md @@ -178,6 +178,7 @@ _Legend: `` means ctrl+b, `` means alt+b, `B` means shift+b_ | `` o `` | 파일 닫기 | Open file in default application. | | `` e `` | 파일 편집 | Open file in external editor. | | `` `` | Line(s)을 패치에 추가/삭제 | | +| `` d `` | Remove lines from commit | Remove the selected lines from this commit. This runs an interactive rebase in the background, so you may get a merge conflict if a later commit also changes these lines. | | `` `` | Exit custom patch builder | | | `` / `` | 검색 시작 | | @@ -337,7 +338,7 @@ _Legend: `` means ctrl+b, `` means alt+b, `B` means shift+b_ | `` `` | 파일명을 클립보드에 복사 | | | `` y `` | 클립보드에 복사 | | | `` c `` | 체크아웃 | Checkout file | -| `` d `` | Remove | Discard this commit's changes to this file | +| `` d `` | View 'discard changes' options | Discard this commit's changes to this file | | `` o `` | 파일 닫기 | Open file in default application. | | `` e `` | Edit | Open file in external editor. | | `` `` | Open external diff tool (git difftool) | | diff --git a/docs-master/keybindings/Keybindings_nl.md b/docs-master/keybindings/Keybindings_nl.md index 0bfffcb3d..ec88b025d 100644 --- a/docs-master/keybindings/Keybindings_nl.md +++ b/docs-master/keybindings/Keybindings_nl.md @@ -138,7 +138,7 @@ _Legend: `` means ctrl+b, `` means alt+b, `B` means shift+b_ | `` `` | Kopieer de bestandsnaam naar het klembord | | | `` y `` | Copy to clipboard | | | `` c `` | Uitchecken | Bestand uitchecken | -| `` d `` | Remove | Uitsluit deze commit zijn veranderingen aan dit bestand | +| `` d `` | Bekijk 'veranderingen ongedaan maken' opties | Uitsluit deze commit zijn veranderingen aan dit bestand | | `` o `` | Open bestand | Open file in default application. | | `` e `` | Edit | Open file in external editor. | | `` `` | Open external diff tool (git difftool) | | @@ -245,6 +245,7 @@ _Legend: `` means ctrl+b, `` means alt+b, `B` means shift+b_ | `` o `` | Open bestand | Open file in default application. | | `` e `` | Verander bestand | Open file in external editor. | | `` `` | Voeg toe/verwijder lijn(en) in patch | | +| `` d `` | Remove lines from commit | Remove the selected lines from this commit. This runs an interactive rebase in the background, so you may get a merge conflict if a later commit also changes these lines. | | `` `` | Sluit lijn-bij-lijn modus | | | `` / `` | Start met zoeken | | diff --git a/docs-master/keybindings/Keybindings_pl.md b/docs-master/keybindings/Keybindings_pl.md index 656f16a76..bb0907326 100644 --- a/docs-master/keybindings/Keybindings_pl.md +++ b/docs-master/keybindings/Keybindings_pl.md @@ -124,6 +124,7 @@ _Legenda: `` oznacza ctrl+b, `` oznacza alt+b, `B` oznacza shift+b_ | `` o `` | Otwórz plik | Otwórz plik w domyślnej aplikacji. | | `` e `` | Edytuj plik | Otwórz plik w zewnętrznym edytorze. | | `` `` | Przełącz linie w łatce | | +| `` d `` | Remove lines from commit | Remove the selected lines from this commit. This runs an interactive rebase in the background, so you may get a merge conflict if a later commit also changes these lines. | | `` `` | Wyjdź z budowniczego niestandardowej łatki | | | `` / `` | Szukaj w bieżącym widoku po tekście | | @@ -268,7 +269,7 @@ _Legenda: `` oznacza ctrl+b, `` oznacza alt+b, `B` oznacza shift+b_ | `` `` | Kopiuj ścieżkę do schowka | | | `` y `` | Kopiuj do schowka | | | `` c `` | Przełącz | Przełącz plik. Zastępuje plik w twoim drzewie roboczym wersją z wybranego commita. | -| `` d `` | Usuń | Odrzuć zmiany w tym pliku z tego commita. Uruchamia interaktywny rebase w tle, więc możesz otrzymać konflikt scalania, jeśli późniejszy commit również zmienia ten plik. | +| `` d `` | Odrzuć | Odrzuć zmiany w tym pliku z tego commita. Uruchamia interaktywny rebase w tle, więc możesz otrzymać konflikt scalania, jeśli późniejszy commit również zmienia ten plik. | | `` o `` | Otwórz plik | Otwórz plik w domyślnej aplikacji. | | `` e `` | Edytuj | Otwórz plik w zewnętrznym edytorze. | | `` `` | Otwórz zewnętrzne narzędzie różnic (git difftool) | | diff --git a/docs-master/keybindings/Keybindings_pt.md b/docs-master/keybindings/Keybindings_pt.md index e7b316e72..d55e4ae1a 100644 --- a/docs-master/keybindings/Keybindings_pt.md +++ b/docs-master/keybindings/Keybindings_pt.md @@ -142,7 +142,7 @@ _Legend: `` means ctrl+b, `` means alt+b, `B` means shift+b_ | `` `` | Copy path to clipboard | | | `` y `` | Copy to clipboard | | | `` c `` | Verificar | Arquivo de check-out. Isso substitui o arquivo em sua árvore de trabalho com a versão do commit selecionado. | -| `` d `` | Remover | Descartar as alterações desse commit para este arquivo. Isso executa uma rebase interativa em segundo plano, então você pode ter um conflito de merge se um commit posterior também alterar este arquivo. | +| `` d `` | Descartar | Descartar as alterações desse commit para este arquivo. Isso executa uma rebase interativa em segundo plano, então você pode ter um conflito de merge se um commit posterior também alterar este arquivo. | | `` o `` | Abrir arquivo | Abrir arquivo no aplicativo padrão. | | `` e `` | Editar | Abrir arquivo no editor externo. | | `` `` | Abrir ferramenta de diff externa (git difftool) | | @@ -295,6 +295,7 @@ _Legend: `` means ctrl+b, `` means alt+b, `B` means shift+b_ | `` o `` | Abrir arquivo | Abrir arquivo no aplicativo padrão. | | `` e `` | Editar arquivo | Abrir arquivo no editor externo. | | `` `` | Alternar linhas no caminho | | +| `` d `` | Remove lines from commit | Remove the selected lines from this commit. This runs an interactive rebase in the background, so you may get a merge conflict if a later commit also changes these lines. | | `` `` | Sair do construtor de patch personalizado | | | `` / `` | Search the current view by text | | diff --git a/docs-master/keybindings/Keybindings_ru.md b/docs-master/keybindings/Keybindings_ru.md index df0a4ce1f..085b4e00b 100644 --- a/docs-master/keybindings/Keybindings_ru.md +++ b/docs-master/keybindings/Keybindings_ru.md @@ -138,6 +138,7 @@ _Связки клавиш_ | `` o `` | Открыть файл | Open file in default application. | | `` e `` | Редактировать файл | Open file in external editor. | | `` `` | Добавить/удалить строку(и) для патча | | +| `` d `` | Remove lines from commit | Remove the selected lines from this commit. This runs an interactive rebase in the background, so you may get a merge conflict if a later commit also changes these lines. | | `` `` | Выйти из сборщика пользовательских патчей | | | `` / `` | Найти | | @@ -296,7 +297,7 @@ _Связки клавиш_ | `` `` | Скопировать название файла в буфер обмена | | | `` y `` | Copy to clipboard | | | `` c `` | Переключить | Переключить файл | -| `` d `` | Remove | Отменить изменения коммита в этом файле | +| `` d `` | Просмотреть параметры «отмены изменении» | Отменить изменения коммита в этом файле | | `` o `` | Открыть файл | Open file in default application. | | `` e `` | Edit | Open file in external editor. | | `` `` | Open external diff tool (git difftool) | | diff --git a/docs-master/keybindings/Keybindings_zh-CN.md b/docs-master/keybindings/Keybindings_zh-CN.md index 169dbb9c8..c29102c3e 100644 --- a/docs-master/keybindings/Keybindings_zh-CN.md +++ b/docs-master/keybindings/Keybindings_zh-CN.md @@ -172,7 +172,7 @@ _图例:`` 意味着ctrl+b, `意味着Alt+b, `B` 意味着shift+b_ | `` `` | 复制路径到剪贴板 | | | `` y `` | 复制到剪贴板 | | | `` c `` | 检出 | 检出文件 | -| `` d `` | 删除 | 放弃对此文件的提交变更 | +| `` d `` | 查看'放弃变更'选项 | 放弃对此文件的提交变更 | | `` o `` | 打开文件 | 使用默认程序打开该文件 | | `` e `` | 编辑(Edit) | 使用外部编辑器打开文件 | | `` `` | 使用外部差异比较工具(git difftool) | | @@ -260,6 +260,7 @@ _图例:`` 意味着ctrl+b, `意味着Alt+b, `B` 意味着shift+b_ | `` o `` | 打开文件 | 使用默认程序打开该文件 | | `` e `` | 编辑文件 | 使用外部编辑器打开文件 | | `` `` | 添加/移除 行到补丁 | | +| `` d `` | Remove lines from commit | Remove the selected lines from this commit. This runs an interactive rebase in the background, so you may get a merge conflict if a later commit also changes these lines. | | `` `` | 退出逐行模式 | | | `` / `` | 开始搜索 | | diff --git a/docs-master/keybindings/Keybindings_zh-TW.md b/docs-master/keybindings/Keybindings_zh-TW.md index 107976c26..c70915ad1 100644 --- a/docs-master/keybindings/Keybindings_zh-TW.md +++ b/docs-master/keybindings/Keybindings_zh-TW.md @@ -72,6 +72,7 @@ _說明:`` 表示 Ctrl+B、`` 表示 Alt+B,`B`表示 Shift+B | `` o `` | 開啟檔案 | 使用預設軟體開啟 | | `` e `` | 編輯檔案 | 使用外部編輯器開啟 | | `` `` | 向 (或從) 補丁中添加/刪除行 | | +| `` d `` | Remove lines from commit | Remove the selected lines from this commit. This runs an interactive rebase in the background, so you may get a merge conflict if a later commit also changes these lines. | | `` `` | 退出自訂補丁建立器 | | | `` / `` | 搜尋 | | @@ -230,7 +231,7 @@ _說明:`` 表示 Ctrl+B、`` 表示 Alt+B,`B`表示 Shift+B | `` `` | 複製檔案名稱到剪貼簿 | | | `` y `` | 複製到剪貼簿 | | | `` c `` | 檢出 | 檢出檔案 | -| `` d `` | Remove | Discard this commit's changes to this file. This runs an interactive rebase in the background, so you may get a merge conflict if a later commit also changes this file. | +| `` d `` | 捨棄 | Discard this commit's changes to this file. This runs an interactive rebase in the background, so you may get a merge conflict if a later commit also changes this file. | | `` o `` | 開啟檔案 | 使用預設軟體開啟 | | `` e `` | 編輯 | 使用外部編輯器開啟 | | `` `` | 開啟外部差異工具 (git difftool) | | diff --git a/pkg/gui/controllers/patch_building_controller.go b/pkg/gui/controllers/patch_building_controller.go index c4f8390f6..f20173d53 100644 --- a/pkg/gui/controllers/patch_building_controller.go +++ b/pkg/gui/controllers/patch_building_controller.go @@ -1,7 +1,10 @@ package controllers import ( + "fmt" + "github.com/jesseduffield/gocui" + "github.com/jesseduffield/lazygit/pkg/gui/keybindings" "github.com/jesseduffield/lazygit/pkg/gui/types" "github.com/samber/lo" ) @@ -42,6 +45,14 @@ func (self *PatchBuildingController) GetKeybindings(opts types.KeybindingsOpts) Description: self.c.Tr.ToggleSelectionForPatch, DisplayOnScreen: true, }, + { + Key: opts.GetKey(opts.Config.Universal.Remove), + Handler: self.discardSelection, + GetDisabledReason: self.getDisabledReasonForDiscard, + Description: self.c.Tr.RemoveSelectionFromPatch, + Tooltip: self.c.Tr.RemoveSelectionFromPatchTooltip, + DisplayOnScreen: true, + }, { Key: opts.GetKey(opts.Config.Universal.Return), Handler: self.Escape, @@ -168,6 +179,70 @@ func (self *PatchBuildingController) toggleSelection() error { return nil } +func (self *PatchBuildingController) getDisabledReasonForDiscard() *types.DisabledReason { + if !self.c.Git().Patch.PatchBuilder.CanRebase { + return &types.DisabledReason{Text: self.c.Tr.CanOnlyDiscardFromLocalCommits, ShowErrorInPanel: true} + } + if self.c.Git().Status.WorkingTreeState().Any() { + return &types.DisabledReason{Text: self.c.Tr.CantPatchWhileRebasingError, ShowErrorInPanel: true} + } + if self.c.UserConfig().Git.DiffContextSize == 0 { + text := fmt.Sprintf(self.c.Tr.Actions.NotEnoughContextToRemoveLines, + keybindings.Label(self.c.UserConfig().Keybinding.Universal.IncreaseContextInDiffView)) + return &types.DisabledReason{Text: text, ShowErrorInPanel: true} + } + return nil +} + +func (self *PatchBuildingController) discardSelection() error { + prompt := lo.Ternary(self.c.Git().Patch.PatchBuilder.IsEmpty(), + self.c.Tr.DiscardLinesFromCommitPrompt, + self.c.Tr.DiscardLinesFromCommitPromptWithReset) + + self.c.Confirm(types.ConfirmOpts{ + Title: self.c.Tr.DiscardLinesFromCommitTitle, + Prompt: prompt, + HandleConfirm: func() error { + return self.discardSelectionFromCommit() + }, + }) + + return nil +} + +func (self *PatchBuildingController) discardSelectionFromCommit() error { + // Reset the current patch if there is one. + if !self.c.Git().Patch.PatchBuilder.IsEmpty() { + self.c.Git().Patch.PatchBuilder.Reset() + } + + if err := self.toggleSelection(); err != nil { + return err + } + + if self.c.Git().Patch.PatchBuilder.IsEmpty() { + return nil + } + + self.c.Helpers().PatchBuilding.Escape() + + return self.c.WithWaitingStatus(self.c.Tr.RebasingStatus, func(gocui.Task) error { + commitIndex := self.getPatchCommitIndex() + self.c.LogAction(self.c.Tr.Actions.RemovePatchFromCommit) + err := self.c.Git().Patch.DeletePatchesFromCommit(self.c.Model().Commits, commitIndex) + return self.c.Helpers().MergeAndRebase.CheckMergeOrRebase(err) + }) +} + +func (self *PatchBuildingController) getPatchCommitIndex() int { + for index, commit := range self.c.Model().Commits { + if commit.Hash() == self.c.Git().Patch.PatchBuilder.To { + return index + } + } + return -1 +} + func (self *PatchBuildingController) Escape() error { context := self.c.Contexts().CustomPatchBuilder state := context.GetState() diff --git a/pkg/i18n/english.go b/pkg/i18n/english.go index 8d66d546a..cf70b3e0b 100644 --- a/pkg/i18n/english.go +++ b/pkg/i18n/english.go @@ -300,6 +300,8 @@ type TranslationSet struct { ToggleSelectHunkTooltip string HunkStagingHint string ToggleSelectionForPatch string + RemoveSelectionFromPatch string + RemoveSelectionFromPatchTooltip string EditHunk string EditHunkTooltip string ToggleStagingView string @@ -688,6 +690,9 @@ type TranslationSet struct { BranchUnknown string DiscardChangeTitle string DiscardChangePrompt string + DiscardLinesFromCommitTitle string + DiscardLinesFromCommitPrompt string + DiscardLinesFromCommitPromptWithReset string CreateNewBranchFromCommit string BuildingPatch string ViewCommits string @@ -1009,6 +1014,7 @@ type Actions struct { ResolveConflictByDeletingFile string NotEnoughContextToStage string NotEnoughContextToDiscard string + NotEnoughContextToRemoveLines string NotEnoughContextForCustomPatch string IgnoreExcludeFile string IgnoreFileErr string @@ -1407,6 +1413,8 @@ func EnglishTranslationSet() *TranslationSet { ToggleSelectHunkTooltip: "Toggle line-by-line vs. hunk selection mode.", HunkStagingHint: englishHunkStagingHint, ToggleSelectionForPatch: `Toggle lines in patch`, + RemoveSelectionFromPatch: `Remove lines from commit`, + RemoveSelectionFromPatchTooltip: "Remove the selected lines from this commit. This runs an interactive rebase in the background, so you may get a merge conflict if a later commit also changes these lines.", EditHunk: `Edit hunk`, EditHunkTooltip: "Edit selected hunk in external editor.", ToggleStagingView: "Switch view", @@ -1798,6 +1806,9 @@ func EnglishTranslationSet() *TranslationSet { BranchUnknown: "Branch unknown", DiscardChangeTitle: "Discard change", DiscardChangePrompt: "Are you sure you want to discard this change (git reset)? It is irreversible.\nTo disable this dialogue set the config key of 'gui.skipDiscardChangeWarning' to true", + DiscardLinesFromCommitTitle: "Discard lines from commit", + DiscardLinesFromCommitPrompt: "Are you sure you want to discard the selected lines from this commit?", + DiscardLinesFromCommitPromptWithReset: "Are you sure you want to discard the selected lines from this commit?\n\nNote: This will reset the active custom patch!", CreateNewBranchFromCommit: "Create new branch off of commit", BuildingPatch: "Building patch", ViewCommits: "View commits", @@ -2079,6 +2090,7 @@ func EnglishTranslationSet() *TranslationSet { ResolveConflictByDeletingFile: "Resolve by deleting file", NotEnoughContextToStage: "Staging or unstaging changes is not possible with a diff context size of 0. Increase the context using '%s'.", NotEnoughContextToDiscard: "Discarding changes is not possible with a diff context size of 0. Increase the context using '%s'.", + NotEnoughContextToRemoveLines: "Removing lines from a commit is not possible with a diff context size of 0. Increase the context using '%s'.", NotEnoughContextForCustomPatch: "Creating custom patches is not possible with a diff context size of 0. Increase the context using '%s'.", IgnoreExcludeFile: "Ignore or exclude file", IgnoreFileErr: "Cannot ignore .gitignore", diff --git a/pkg/integration/tests/patch_building/discard_lines_from_commit.go b/pkg/integration/tests/patch_building/discard_lines_from_commit.go new file mode 100644 index 000000000..ab1414053 --- /dev/null +++ b/pkg/integration/tests/patch_building/discard_lines_from_commit.go @@ -0,0 +1,63 @@ +package patch_building + +import ( + "github.com/jesseduffield/lazygit/pkg/config" + . "github.com/jesseduffield/lazygit/pkg/integration/components" +) + +var DiscardLinesFromCommit = NewIntegrationTest(NewIntegrationTestArgs{ + Description: "Discard specific lines from a commit using the 'd' shortcut in the patch building view", + ExtraCmdArgs: []string{}, + Skip: false, + SetupConfig: func(config *config.AppConfig) {}, + SetupRepo: func(shell *Shell) { + shell.EmptyCommit("first commit") + + shell.CreateFileAndAdd("file1", "1st line\n2nd line\n3rd line\n") + shell.Commit("commit to remove from") + }, + Run: func(t *TestDriver, keys config.KeybindingConfig) { + t.Views().Commits(). + Focus(). + Lines( + Contains("commit to remove from").IsSelected(), + Contains("first commit"), + ). + PressEnter() + + t.Views().CommitFiles(). + IsFocused(). + Lines( + Contains("A file1").IsSelected(), + ). + PressEnter() + + // Select the second line (+2nd line) and press 'd' to remove it + t.Views().PatchBuilding(). + IsFocused(). + SelectNextItem(). + SelectedLines( + Contains("+2nd line"), + ). + Press(keys.Universal.Remove) + + t.ExpectPopup().Confirmation(). + Title(Equals("Discard lines from commit")). + Content(Equals("Are you sure you want to discard the selected lines from this commit?")). + Confirm() + + // After the rebase, we should be back at the commit files view + // and the commit should now only contain the 1st and 3rd lines + t.Views().CommitFiles(). + IsFocused(). + Lines( + Contains("A file1").IsSelected(), + ). + PressEscape() + + t.Views().Main().ContainsLines( + Equals("+1st line"), + Equals("+3rd line"), + ) + }, +}) diff --git a/pkg/integration/tests/test_list.go b/pkg/integration/tests/test_list.go index 4d9edaa70..804a8764f 100644 --- a/pkg/integration/tests/test_list.go +++ b/pkg/integration/tests/test_list.go @@ -328,6 +328,7 @@ var tests = []*components.IntegrationTest{ patch_building.ApplyInReverseWithConflict, patch_building.ApplyWithModifiedFileConflict, patch_building.ApplyWithModifiedFileNoConflict, + patch_building.DiscardLinesFromCommit, patch_building.EditLineInPatchBuildingPanel, patch_building.MoveRangeToIndex, patch_building.MoveToEarlierCommit,