{"record":{"id":"906a2fd1994e4318","repo":"jesseduffield/lazygit","slug":"creating-custom-patches-is-not-possible-with-a-dif","errorCode":null,"errorMessage":"Creating custom patches is not possible with a diff context size of 0. Increase the context using '%s'.","messagePattern":"Creating custom patches is not possible with a diff context size of 0\\. Increase the context using '(.+?)'\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"pkg/gui/controllers/commits_files_controller.go","lineNumber":449,"sourceCode":"\nfunc (self *CommitFilesController) openDiffTool(node *filetree.CommitFileNode) error {\n\tfrom, to := self.context().GetFromAndToForDiff()\n\tfrom, reverse := self.c.Modes().Diffing.GetFromAndReverseArgsForDiff(from)\n\t_, err := self.c.RunSubprocess(self.c.Git().Diff.OpenDiffToolCmdObj(\n\t\tgit_commands.DiffToolCmdOptions{\n\t\t\tFilepath:    node.GetPath(),\n\t\t\tFromCommit:  from,\n\t\t\tToCommit:    to,\n\t\t\tReverse:     reverse,\n\t\t\tIsDirectory: !node.IsFile(),\n\t\t\tStaged:      false,\n\t\t}))\n\treturn err\n}\n\nfunc (self *CommitFilesController) toggleForPatch(selectedNodes []*filetree.CommitFileNode) error {\n\tif self.c.UserConfig().Git.DiffContextSize == 0 {\n\t\treturn fmt.Errorf(self.c.Tr.Actions.NotEnoughContextForCustomPatch,\n\t\t\tself.c.UserConfig().Keybinding.Universal.IncreaseContextInDiffView)\n\t}\n\n\trefName := self.context().GetRef().RefName()\n\n\ttoggle := func() error {\n\t\treturn self.c.WithWaitingStatus(self.c.Tr.UpdatingPatch, func(gocui.Task) error {\n\t\t\tselectedNodes = normalisedSelectedCommitFileNodes(selectedNodes)\n\n\t\t\t// Find if any file in the selection is unselected or partially added\n\t\t\tadding := lo.SomeBy(selectedNodes, func(node *filetree.CommitFileNode) bool {\n\t\t\t\treturn node.SomeFile(func(file *models.CommitFile) bool {\n\t\t\t\t\tfileStatus := self.c.Git().Patch.PatchBuilder.GetFileStatus(file.Path, refName)\n\t\t\t\t\treturn fileStatus == patch.PART || fileStatus == patch.UNSELECTED\n\t\t\t\t})\n\t\t\t})\n\n\t\t\tpatchOperationFunction := self.c.Git().Patch.PatchBuilder.RemoveFile","sourceCodeStart":431,"sourceCodeEnd":467,"githubUrl":"https://github.com/jesseduffield/lazygit/blob/c477a2959b229fbf3284be0d4d2904ab61ec3c94/pkg/gui/controllers/commits_files_controller.go#L431-L467","documentation":"CommitFilesController.toggleForPatch (pkg/gui/controllers/commits_files_controller.go) refuses to add/remove files to a custom patch when user config git.diffContextSize is 0. Building a patch needs at least one context line to know where hunk boundaries are, so with zero context lazygit returns the translated NotEnoughContextForCustomPatch action error and suggests the IncreaseContextInDiffView key.","triggerScenarios":"Setting `git.diffContextSize: 0` in the config (or lowering context to 0 with the decrease-context key), then pressing the toggle-patch key (default 'space' in the commit-files view while building a custom patch).","commonSituations":"Users who set diffContextSize 0 for compact diffs and later try to build a custom patch or move lines between commits; scripts/tests that run with a minimal config.","solutions":["Press the increase-diff-context key (default '}') at least once before toggling patch entries.","Or set git.diffContextSize to 1 or higher in the user config and restart.","If a helper script drives lazygit, ensure its config sets a non-zero context."],"exampleFix":"# before (user config.yml)\ngit:\n  diffContextSize: 0\n\n# after\ngit:\n  diffContextSize: 3","handlingStrategy":"validation","validationCode":"if cfg.Git.DiffContextSize == 0 {\n\treturn errors.New(\"raise git.diffContextSize before building custom patches\")\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep git.diffContextSize >= 1 whenever you use custom patches.","Learn the '}' key: it raises context in-place when the error appears.","Scripts driving lazygit should always pin a non-zero context."],"tags":["config","patch","diff-context"],"backgroundTag":null,"analyzedSha":"c477a2959b229fbf3284be0d4d2904ab61ec3c94","analyzedAt":"2026-08-15T08:34:32.451Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}