diff options
Diffstat (limited to 'pkg/commands')
-rw-r--r-- | pkg/commands/git.go | 8 | ||||
-rw-r--r-- | pkg/commands/patch_manager.go | 32 | ||||
-rw-r--r-- | pkg/commands/patch_rebases.go | 8 |
3 files changed, 32 insertions, 16 deletions
diff --git a/pkg/commands/git.go b/pkg/commands/git.go index 42c1749af..1448b37cb 100644 --- a/pkg/commands/git.go +++ b/pkg/commands/git.go @@ -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) { diff --git a/pkg/commands/patch_manager.go b/pkg/commands/patch_manager.go index 1c747c33d..4abf737a0 100644 --- a/pkg/commands/patch_manager.go +++ b/pkg/commands/patch_manager.go @@ -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 +} diff --git a/pkg/commands/patch_rebases.go b/pkg/commands/patch_rebases.go index f0dadbc16..19116e071 100644 --- a/pkg/commands/patch_rebases.go +++ b/pkg/commands/patch_rebases.go @@ -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 } |