From 005318cbb29cf535c636da49464f0d1c82c71bbc Mon Sep 17 00:00:00 2001 From: Chen Linxuan Date: Tue, 29 Apr 2025 10:29:39 +0800 Subject: [PATCH] Fix git apply error during applying custom patch Man page of `git apply` says that: --unidiff-zero By default, git apply expects that the patch being applied is a unified diff with at least one line of context. This provides good safety measures, but breaks down when applying a diff generated with --unified=0. To bypass these checks use --unidiff-zero. Note, for the reasons stated above, the usage of context-free patches is discouraged. Lazygit always render custom patch with zero context, so this --unidiff-zero option is needed when pass such patch to `git apply`. Check https://github.com/black-desk/lazygit-bug-report-2025-04-29 for details. --- pkg/commands/git_commands/patch.go | 1 + 1 file changed, 1 insertion(+) diff --git a/pkg/commands/git_commands/patch.go b/pkg/commands/git_commands/patch.go index 77563ab88bb..90b14ed3ab0 100644 --- a/pkg/commands/git_commands/patch.go +++ b/pkg/commands/git_commands/patch.go @@ -71,6 +71,7 @@ func (self *PatchCommands) applyPatchFile(filepath string, opts ApplyPatchOpts) ArgIf(opts.Cached, "--cached"). ArgIf(opts.Index, "--index"). ArgIf(opts.Reverse, "--reverse"). + Arg("--unidiff-zero"). Arg(filepath). ToArgv()