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 <copilot@github.com>
This commit is contained in:
Stefan Haller
2026-10-04 19:01:03 +02:00
co-authored by GitHub Copilot
parent ca8223caad
commit c3ba2c4295
4 changed files with 55 additions and 19 deletions
@@ -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
}
-2
View File
@@ -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",
@@ -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"),
)
},
})
+1
View File
@@ -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,