mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-07-30 03:23:08 +03:00
use fallback approach for applying patch
This commit is contained in:
@ -610,6 +610,7 @@ func (c *GitCommand) Diff(file *File, plain bool, cached bool) string {
|
||||
}
|
||||
|
||||
func (c *GitCommand) ApplyPatch(patch string, reverse bool, cached bool, extraFlags string) error {
|
||||
c.Log.Warn(patch)
|
||||
filepath := filepath.Join(c.Config.GetUserConfigDir(), utils.GetCurrentRepoName(), time.Now().Format(time.StampNano)+".patch")
|
||||
if err := c.OSCommand.CreateFileWithContent(filepath, patch); err != nil {
|
||||
return err
|
||||
|
@ -87,7 +87,7 @@ func (p *PatchManager) RemoveFileLineRange(filename string, firstLineIdx, lastLi
|
||||
}
|
||||
}
|
||||
|
||||
func (p *PatchManager) RenderPlainPatchForFile(filename string, reverse bool) string {
|
||||
func (p *PatchManager) RenderPlainPatchForFile(filename string, reverse bool, keepOriginalHeader bool) string {
|
||||
info := p.fileInfoMap[filename]
|
||||
if info == nil {
|
||||
return ""
|
||||
@ -101,14 +101,14 @@ func (p *PatchManager) RenderPlainPatchForFile(filename string, reverse bool) st
|
||||
case PART:
|
||||
// generate a new diff with just the selected lines
|
||||
m := NewPatchModifier(p.Log, filename, info.diff)
|
||||
return m.ModifiedPatchForLines(info.includedLineIndices, reverse, true)
|
||||
return m.ModifiedPatchForLines(info.includedLineIndices, reverse, keepOriginalHeader)
|
||||
default:
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
||||
func (p *PatchManager) RenderPatchForFile(filename string, plain bool, reverse bool) string {
|
||||
patch := p.RenderPlainPatchForFile(filename, reverse)
|
||||
func (p *PatchManager) RenderPatchForFile(filename string, plain bool, reverse bool, keepOriginalHeader bool) string {
|
||||
patch := p.RenderPlainPatchForFile(filename, reverse, keepOriginalHeader)
|
||||
if plain {
|
||||
return patch
|
||||
}
|
||||
@ -133,7 +133,7 @@ func (p *PatchManager) RenderEachFilePatch(plain bool) []string {
|
||||
sort.Strings(filenames)
|
||||
output := []string{}
|
||||
for _, filename := range filenames {
|
||||
patch := p.RenderPatchForFile(filename, plain, false)
|
||||
patch := p.RenderPatchForFile(filename, plain, false, true)
|
||||
if patch != "" {
|
||||
output = append(output, patch)
|
||||
}
|
||||
@ -180,11 +180,20 @@ func (p *PatchManager) ApplyPatches(reverse bool) error {
|
||||
}
|
||||
}
|
||||
|
||||
patch := p.RenderPatchForFile(filename, true, reverseOnGenerate)
|
||||
var err error
|
||||
// first run we try with the original header, then without
|
||||
for _, keepOriginalHeader := range []bool{true, false} {
|
||||
patch := p.RenderPatchForFile(filename, true, reverseOnGenerate, keepOriginalHeader)
|
||||
if patch == "" {
|
||||
continue
|
||||
}
|
||||
if err := p.ApplyPatch(patch, reverseOnApply, false, "--index --3way"); err != nil {
|
||||
if err = p.ApplyPatch(patch, reverseOnApply, false, "--index --3way"); err != nil {
|
||||
continue
|
||||
}
|
||||
break
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
@ -68,7 +68,7 @@ func (gui *Gui) refreshStagingPanel() error {
|
||||
return err
|
||||
}
|
||||
|
||||
secondaryColorDiff := gui.GitCommand.PatchManager.RenderPatchForFile(commitFile.Name, false, false)
|
||||
secondaryColorDiff := gui.GitCommand.PatchManager.RenderPatchForFile(commitFile.Name, false, false, true)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
Reference in New Issue
Block a user