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 {
|
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")
|
filepath := filepath.Join(c.Config.GetUserConfigDir(), utils.GetCurrentRepoName(), time.Now().Format(time.StampNano)+".patch")
|
||||||
if err := c.OSCommand.CreateFileWithContent(filepath, patch); err != nil {
|
if err := c.OSCommand.CreateFileWithContent(filepath, patch); err != nil {
|
||||||
return err
|
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]
|
info := p.fileInfoMap[filename]
|
||||||
if info == nil {
|
if info == nil {
|
||||||
return ""
|
return ""
|
||||||
@ -101,14 +101,14 @@ func (p *PatchManager) RenderPlainPatchForFile(filename string, reverse bool) st
|
|||||||
case PART:
|
case PART:
|
||||||
// generate a new diff with just the selected lines
|
// generate a new diff with just the selected lines
|
||||||
m := NewPatchModifier(p.Log, filename, info.diff)
|
m := NewPatchModifier(p.Log, filename, info.diff)
|
||||||
return m.ModifiedPatchForLines(info.includedLineIndices, reverse, true)
|
return m.ModifiedPatchForLines(info.includedLineIndices, reverse, keepOriginalHeader)
|
||||||
default:
|
default:
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *PatchManager) RenderPatchForFile(filename string, plain bool, reverse bool) string {
|
func (p *PatchManager) RenderPatchForFile(filename string, plain bool, reverse bool, keepOriginalHeader bool) string {
|
||||||
patch := p.RenderPlainPatchForFile(filename, reverse)
|
patch := p.RenderPlainPatchForFile(filename, reverse, keepOriginalHeader)
|
||||||
if plain {
|
if plain {
|
||||||
return patch
|
return patch
|
||||||
}
|
}
|
||||||
@ -133,7 +133,7 @@ func (p *PatchManager) RenderEachFilePatch(plain bool) []string {
|
|||||||
sort.Strings(filenames)
|
sort.Strings(filenames)
|
||||||
output := []string{}
|
output := []string{}
|
||||||
for _, filename := range filenames {
|
for _, filename := range filenames {
|
||||||
patch := p.RenderPatchForFile(filename, plain, false)
|
patch := p.RenderPatchForFile(filename, plain, false, true)
|
||||||
if patch != "" {
|
if patch != "" {
|
||||||
output = append(output, 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
|
||||||
if patch == "" {
|
// first run we try with the original header, then without
|
||||||
continue
|
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 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
break
|
||||||
}
|
}
|
||||||
if err := p.ApplyPatch(patch, reverseOnApply, false, "--index --3way"); err != nil {
|
|
||||||
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -68,7 +68,7 @@ func (gui *Gui) refreshStagingPanel() error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
secondaryColorDiff := gui.GitCommand.PatchManager.RenderPatchForFile(commitFile.Name, false, false)
|
secondaryColorDiff := gui.GitCommand.PatchManager.RenderPatchForFile(commitFile.Name, false, false, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user