summaryrefslogtreecommitdiffstats
path: root/pkg/commands
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2020-08-21 20:31:21 +1000
committerJesse Duffield <jessedduffield@gmail.com>2020-08-23 14:29:18 +1000
commite6a1bd656620d2b786266b593b197721d669085a (patch)
tree1c515c9856ad0e4bcbf3a66ba09c09e22e0d7c0d /pkg/commands
parent609f3f4bfaa71e0d94eac845ee0f8f6ffcf2e624 (diff)
generalise patch building stuff
Diffstat (limited to 'pkg/commands')
-rw-r--r--pkg/commands/git.go2
-rw-r--r--pkg/commands/patch/patch_manager.go20
2 files changed, 13 insertions, 9 deletions
diff --git a/pkg/commands/git.go b/pkg/commands/git.go
index 243457c4f..ddb19f98a 100644
--- a/pkg/commands/git.go
+++ b/pkg/commands/git.go
@@ -1061,7 +1061,7 @@ func (c *GitCommand) GetFilesInRef(parent string, isStash bool, patchManager *pa
for _, file := range strings.Split(strings.TrimRight(files, "\n"), "\n") {
status := patch.UNSELECTED
- if patchManager != nil && patchManager.CommitSha == parent {
+ if patchManager != nil && patchManager.Parent == parent {
status = patchManager.GetFileStatus(file)
}
diff --git a/pkg/commands/patch/patch_manager.go b/pkg/commands/patch/patch_manager.go
index d248381f6..8da6fb3a2 100644
--- a/pkg/commands/patch/patch_manager.go
+++ b/pkg/commands/patch/patch_manager.go
@@ -12,7 +12,7 @@ const (
UNSELECTED = iota
// WHOLE is for when you want to add the whole diff of a file to the patch,
// including e.g. if it was deleted
- WHOLE = iota
+ WHOLE
// PART is for when you're only talking about specific lines that have been modified
PART
)
@@ -25,9 +25,13 @@ type fileInfo struct {
type applyPatchFunc func(patch string, flags ...string) error
-// PatchManager manages the building of a patch for a commit to be applied to another commit (or the working tree, or removed from the current commit)
+// PatchManager manages the building of a patch for a commit to be applied to another commit (or the working tree, or removed from the current commit). We also support building patches from things like stashes, for which there is less flexibility
type PatchManager struct {
- CommitSha string
+ // Parent is the commit sha if we're dealing with files of a commit, or a stash ref for a stash
+ Parent string
+
+ // CanRebase tells us whether we're allowed to modify our commits. CanRebase should be true for commits of the currently checked out branch and false for everything else
+ CanRebase bool
fileInfoMap map[string]*fileInfo
Log *logrus.Entry
ApplyPatch applyPatchFunc
@@ -42,8 +46,8 @@ func NewPatchManager(log *logrus.Entry, applyPatch applyPatchFunc) *PatchManager
}
// NewPatchManager returns a new PatchManager
-func (p *PatchManager) Start(commitSha string, diffMap map[string]string) {
- p.CommitSha = commitSha
+func (p *PatchManager) Start(parent string, diffMap map[string]string) {
+ p.Parent = parent
p.fileInfoMap = map[string]*fileInfo{}
for filename, diff := range diffMap {
p.fileInfoMap[filename] = &fileInfo{
@@ -219,12 +223,12 @@ func (p *PatchManager) ApplyPatches(reverse bool) error {
// clears the patch
func (p *PatchManager) Reset() {
- p.CommitSha = ""
+ p.Parent = ""
p.fileInfoMap = map[string]*fileInfo{}
}
-func (p *PatchManager) CommitSelected() bool {
- return p.CommitSha != ""
+func (p *PatchManager) Active() bool {
+ return p.Parent != ""
}
func (p *PatchManager) IsEmpty() bool {