From 2d32d6f0c272340256db45674d88080e2a3be0f1 Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Thu, 20 Aug 2026 21:26:21 +0200 Subject: [PATCH] Allow context changes while building a custom patch The focused diff addresses patch lines by identity, so changing how much context is rendered cannot invalidate an active patch. Remove the explorer era refusal and prove that another line can still be toggled correctly after the rerender. Co-Authored-By: GitHub Copilot --- .../controllers/context_lines_controller.go | 17 ------ pkg/i18n/english.go | 2 - ...hange_context_size_while_building_patch.go | 54 +++++++++++++++++++ pkg/integration/tests/test_list.go | 1 + 4 files changed, 55 insertions(+), 19 deletions(-) create mode 100644 pkg/integration/tests/main_view/change_context_size_while_building_patch.go diff --git a/pkg/gui/controllers/context_lines_controller.go b/pkg/gui/controllers/context_lines_controller.go index 9a35f41b2..366429a50 100644 --- a/pkg/gui/controllers/context_lines_controller.go +++ b/pkg/gui/controllers/context_lines_controller.go @@ -1,7 +1,6 @@ package controllers import ( - "errors" "fmt" "math" @@ -50,10 +49,6 @@ func (self *ContextLinesController) Context() types.Context { } func (self *ContextLinesController) Increase() error { - if err := self.checkCanChangeContext(); err != nil { - return err - } - if self.c.UserConfig().Git.DiffContextSize < math.MaxUint64 { self.c.UserConfig().Git.DiffContextSize++ } @@ -61,10 +56,6 @@ func (self *ContextLinesController) Increase() error { } func (self *ContextLinesController) Decrease() error { - if err := self.checkCanChangeContext(); err != nil { - return err - } - if self.c.UserConfig().Git.DiffContextSize > 0 { self.c.UserConfig().Git.DiffContextSize-- } @@ -83,11 +74,3 @@ func (self *ContextLinesController) applyChange() error { currentContext.HandleRenderToMain() return nil } - -func (self *ContextLinesController) checkCanChangeContext() error { - if self.c.Git().Patch.PatchBuilder.Active() { - return errors.New(self.c.Tr.CantChangeContextSizeError) - } - - return nil -} diff --git a/pkg/i18n/english.go b/pkg/i18n/english.go index 100b0a6cd..8571f33e7 100644 --- a/pkg/i18n/english.go +++ b/pkg/i18n/english.go @@ -863,7 +863,6 @@ type TranslationSet struct { SortOrderPrompt string SortCommits string SortCommitsTooltip string - CantChangeContextSizeError string CantChangeRenameThresholdError string OpenCommitInBrowser string ViewBisectOptions string @@ -2043,7 +2042,6 @@ func EnglishTranslationSet() *TranslationSet { SortBasedOnReflog: "(based on reflog)", SortCommits: "Commit sort order", SortCommitsTooltip: "Change the sort order of the commits in the commit log.\n\nThe default can be changed in the config file with the key 'git.log.sortOrder'.", - CantChangeContextSizeError: "Cannot change context while in patch building mode because we were too lazy to support it when releasing the feature. If you really want it, please let us know!", CantChangeRenameThresholdError: "Cannot change the rename similarity threshold while in patch building mode, because the custom patch can't cope with a rename turning into a delete and add underneath it.", OpenCommitInBrowser: "Open commit in browser", ViewBisectOptions: "View bisect options", diff --git a/pkg/integration/tests/main_view/change_context_size_while_building_patch.go b/pkg/integration/tests/main_view/change_context_size_while_building_patch.go new file mode 100644 index 000000000..d355dd047 --- /dev/null +++ b/pkg/integration/tests/main_view/change_context_size_while_building_patch.go @@ -0,0 +1,54 @@ +package main_view + +import ( + "github.com/jesseduffield/lazygit/pkg/config" + . "github.com/jesseduffield/lazygit/pkg/integration/components" +) + +var ChangeContextSizeWhileBuildingPatch = NewIntegrationTest(NewIntegrationTestArgs{ + Description: "Change diff context size while building a custom patch, then add another line", + ExtraCmdArgs: []string{}, + Skip: false, + SetupConfig: func(config *config.AppConfig) { + config.GetUserConfig().Gui.UseHunkModeInStagingView = false + config.GetUserConfig().Git.DiffContextSize = 1 + }, + SetupRepo: func(shell *Shell) { + shell.CreateFileAndAdd("file1", "one\ntwo\nthree\nfour\nfive\nsix\nseven\neight\nnine\nten\n") + shell.Commit("first commit") + shell.UpdateFileAndAdd("file1", "ONE\ntwo\nthree\nfour\nfive\nsix\nseven\neight\nnine\nTEN\n") + shell.Commit("second commit") + }, + Run: func(t *TestDriver, keys config.KeybindingConfig) { + t.Views().Commits(). + Focus(). + Lines( + Contains("second commit").IsSelected(), + Contains("first commit"), + ). + PressEnter() + + t.Views().CommitFiles(). + IsFocused(). + Press(keys.Universal.FocusMainView) + + t.Views().Main(). + IsFocused(). + SelectedLines(Contains("-one")). + PressPrimaryAction(). + Press(keys.Universal.IncreaseContextInDiffView). + Tap(func() { + t.ExpectToast(Equals("Changed diff context size to 2")) + }). + NavigateToLine(Contains("-ten")). + PressPrimaryAction() + + t.Views().Secondary().Content( + Contains("-one").Contains("-ten"), + ) + t.Views().Main().MarkedLines( + Contains("-one"), + Contains("-ten"), + ) + }, +}) diff --git a/pkg/integration/tests/test_list.go b/pkg/integration/tests/test_list.go index ab5a9fbe3..567402ae6 100644 --- a/pkg/integration/tests/test_list.go +++ b/pkg/integration/tests/test_list.go @@ -376,6 +376,7 @@ var tests = []*components.IntegrationTest{ main_view.BuildPatchFromAReflogEntry, main_view.BuildPatchFromAWholeCommitsDiff, main_view.BuildPatchWithMixedSelections, + main_view.ChangeContextSizeWhileBuildingPatch, main_view.ChangeScreenModeInFocusedDiff, main_view.ClickSelectsDiffLine, main_view.CommitFromMainView,