mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-07-28 16:02:01 +03:00
don't let patch manager ever be nil
This commit is contained in:
@ -109,7 +109,7 @@ func NewGitCommand(log *logrus.Entry, osCommand *OSCommand, tr *i18n.Localizer,
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &GitCommand{
|
||||
gitCommand := &GitCommand{
|
||||
Log: log,
|
||||
OSCommand: osCommand,
|
||||
Tr: tr,
|
||||
@ -120,7 +120,11 @@ func NewGitCommand(log *logrus.Entry, osCommand *OSCommand, tr *i18n.Localizer,
|
||||
getLocalGitConfig: gitconfig.Local,
|
||||
removeFile: os.RemoveAll,
|
||||
DotGitDir: dotGitDir,
|
||||
}, nil
|
||||
}
|
||||
|
||||
gitCommand.PatchManager = NewPatchManager(log, gitCommand.ApplyPatch)
|
||||
|
||||
return gitCommand, nil
|
||||
}
|
||||
|
||||
func findDotGitDir(stat func(string) (os.FileInfo, error), readFile func(filename string) ([]byte, error)) (string, error) {
|
||||
|
@ -25,21 +25,23 @@ type PatchManager struct {
|
||||
}
|
||||
|
||||
// NewPatchManager returns a new PatchModifier
|
||||
func NewPatchManager(log *logrus.Entry, applyPatch applyPatchFunc, commitSha string, diffMap map[string]string) *PatchManager {
|
||||
infoMap := map[string]*fileInfo{}
|
||||
func NewPatchManager(log *logrus.Entry, applyPatch applyPatchFunc) *PatchManager {
|
||||
return &PatchManager{
|
||||
Log: log,
|
||||
ApplyPatch: applyPatch,
|
||||
}
|
||||
}
|
||||
|
||||
// NewPatchManager returns a new PatchModifier
|
||||
func (p *PatchManager) Start(commitSha string, diffMap map[string]string) {
|
||||
p.CommitSha = commitSha
|
||||
p.fileInfoMap = map[string]*fileInfo{}
|
||||
for filename, diff := range diffMap {
|
||||
infoMap[filename] = &fileInfo{
|
||||
p.fileInfoMap[filename] = &fileInfo{
|
||||
mode: UNSELECTED,
|
||||
diff: diff,
|
||||
}
|
||||
}
|
||||
|
||||
return &PatchManager{
|
||||
Log: log,
|
||||
fileInfoMap: infoMap,
|
||||
CommitSha: commitSha,
|
||||
ApplyPatch: applyPatch,
|
||||
}
|
||||
}
|
||||
|
||||
func (p *PatchManager) AddFile(filename string) {
|
||||
@ -200,3 +202,13 @@ func (p *PatchManager) ApplyPatches(reverse bool) error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// clears the patch
|
||||
func (p *PatchManager) Reset() {
|
||||
p.CommitSha = ""
|
||||
p.fileInfoMap = map[string]*fileInfo{}
|
||||
}
|
||||
|
||||
func (p *PatchManager) IsEmpty() bool {
|
||||
return p != nil && p.CommitSha == "" || len(p.fileInfoMap) == 0
|
||||
}
|
||||
|
@ -22,7 +22,7 @@ func (c *GitCommand) DeletePatchesFromCommit(commits []*Commit, commitIndex int,
|
||||
}
|
||||
|
||||
c.onSuccessfulContinue = func() error {
|
||||
c.PatchManager = nil
|
||||
c.PatchManager.Reset()
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -50,7 +50,7 @@ func (c *GitCommand) MovePatchToSelectedCommit(commits []*Commit, sourceCommitId
|
||||
}
|
||||
|
||||
c.onSuccessfulContinue = func() error {
|
||||
c.PatchManager = nil
|
||||
c.PatchManager.Reset()
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -121,7 +121,7 @@ func (c *GitCommand) MovePatchToSelectedCommit(commits []*Commit, sourceCommitId
|
||||
}
|
||||
|
||||
c.onSuccessfulContinue = func() error {
|
||||
c.PatchManager = nil
|
||||
c.PatchManager.Reset()
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -161,7 +161,7 @@ func (c *GitCommand) PullPatchIntoIndex(commits []*Commit, commitIdx int, p *Pat
|
||||
return err
|
||||
}
|
||||
|
||||
c.PatchManager = nil
|
||||
c.PatchManager.Reset()
|
||||
return nil
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user