mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-06-15 00:15:32 +02:00
Fix custom patch operations on added files
Several custom patch commands on parts of an added file would fail with the confusing error message "error: new file XXX depends on old contents". These were dropping the custom patch from the original commit, moving the patch to a new commit, moving it to a later commit, or moving it to the index. We fix this by converting the patch header from an added file to a diff against an empty file. We do this not just for the purpose of applying the patch, but also for rendering it and copying it to the clip board. I'm not sure it matters much in these cases, but it does feel more correct for a filtered patch to be presented this way.
This commit is contained in:
@ -47,8 +47,8 @@ type ApplyPatchOpts struct {
|
||||
Reverse bool
|
||||
}
|
||||
|
||||
func (self *PatchCommands) ApplyCustomPatch(reverse bool) error {
|
||||
patch := self.PatchBuilder.PatchToApply(reverse)
|
||||
func (self *PatchCommands) ApplyCustomPatch(reverse bool, turnAddedFilesIntoDiffAgainstEmptyFile bool) error {
|
||||
patch := self.PatchBuilder.PatchToApply(reverse, turnAddedFilesIntoDiffAgainstEmptyFile)
|
||||
|
||||
return self.ApplyPatch(patch, ApplyPatchOpts{
|
||||
Index: true,
|
||||
@ -94,7 +94,7 @@ func (self *PatchCommands) DeletePatchesFromCommit(commits []*models.Commit, com
|
||||
}
|
||||
|
||||
// apply each patch in reverse
|
||||
if err := self.ApplyCustomPatch(true); err != nil {
|
||||
if err := self.ApplyCustomPatch(true, true); err != nil {
|
||||
_ = self.rebase.AbortRebase()
|
||||
return err
|
||||
}
|
||||
@ -123,7 +123,7 @@ func (self *PatchCommands) MovePatchToSelectedCommit(commits []*models.Commit, s
|
||||
}
|
||||
|
||||
// apply each patch forward
|
||||
if err := self.ApplyCustomPatch(false); err != nil {
|
||||
if err := self.ApplyCustomPatch(false, false); err != nil {
|
||||
// Don't abort the rebase here; this might cause conflicts, so give
|
||||
// the user a chance to resolve them
|
||||
return err
|
||||
@ -172,7 +172,7 @@ func (self *PatchCommands) MovePatchToSelectedCommit(commits []*models.Commit, s
|
||||
}
|
||||
|
||||
// apply each patch in reverse
|
||||
if err := self.ApplyCustomPatch(true); err != nil {
|
||||
if err := self.ApplyCustomPatch(true, true); err != nil {
|
||||
_ = self.rebase.AbortRebase()
|
||||
return err
|
||||
}
|
||||
@ -228,7 +228,7 @@ func (self *PatchCommands) MovePatchIntoIndex(commits []*models.Commit, commitId
|
||||
return err
|
||||
}
|
||||
|
||||
if err := self.ApplyCustomPatch(true); err != nil {
|
||||
if err := self.ApplyCustomPatch(true, true); err != nil {
|
||||
if self.status.WorkingTreeState() == enums.REBASE_MODE_REBASING {
|
||||
_ = self.rebase.AbortRebase()
|
||||
}
|
||||
@ -282,7 +282,7 @@ func (self *PatchCommands) PullPatchIntoNewCommit(
|
||||
return err
|
||||
}
|
||||
|
||||
if err := self.ApplyCustomPatch(true); err != nil {
|
||||
if err := self.ApplyCustomPatch(true, true); err != nil {
|
||||
_ = self.rebase.AbortRebase()
|
||||
return err
|
||||
}
|
||||
|
Reference in New Issue
Block a user