summaryrefslogtreecommitdiffstats
path: root/pkg/commands/patch_rebases.go
diff options
context:
space:
mode:
authorGary Yendell <gary.yendell@diamond.ac.uk>2020-04-27 17:31:22 +0100
committerJesse Duffield <jessedduffield@gmail.com>2020-05-09 11:59:37 +1000
commit7ed8ee160d7f1d38f5159dca315e56899de8c0b9 (patch)
tree51b95d8e77a392f5c40994a0d54372386af3030f /pkg/commands/patch_rebases.go
parent3dd33b65a04b95c33b4cf154d41e8ab08d8aa9e2 (diff)
Add option to split patch into a new commit
Add GetHeadCommitMessage to read the subject of the HEAD commit Create PullPatchIntoNewCommit based heavily on PullPatchIntoIndex to split the current patch from its commit and apply it in a separate commit immediately after. WIP to Squash - Fill format string with format string WIP
Diffstat (limited to 'pkg/commands/patch_rebases.go')
-rw-r--r--pkg/commands/patch_rebases.go45
1 files changed, 44 insertions, 1 deletions
diff --git a/pkg/commands/patch_rebases.go b/pkg/commands/patch_rebases.go
index eeeb0876c..bb1ca5b98 100644
--- a/pkg/commands/patch_rebases.go
+++ b/pkg/commands/patch_rebases.go
@@ -1,6 +1,9 @@
package commands
-import "github.com/go-errors/errors"
+import (
+ "fmt"
+ "github.com/go-errors/errors"
+)
// DeletePatchesFromCommit applies a patch in reverse for a commit
func (c *GitCommand) DeletePatchesFromCommit(commits []*Commit, commitIndex int, p *PatchManager) error {
@@ -183,3 +186,43 @@ func (c *GitCommand) PullPatchIntoIndex(commits []*Commit, commitIdx int, p *Pat
return c.GenericMerge("rebase", "continue")
}
+
+func (c *GitCommand) PullPatchIntoNewCommit(commits []*Commit, commitIdx int, p *PatchManager) error {
+ if err := c.BeginInteractiveRebaseForCommit(commits, commitIdx); err != nil {
+ return err
+ }
+
+ if err := p.ApplyPatches(true); err != nil {
+ if err := c.GenericMerge("rebase", "abort"); err != nil {
+ return err
+ }
+ return err
+ }
+
+ // amend the commit
+ if _, err := c.AmendHead(); err != nil {
+ return err
+ }
+
+ // add patches to index
+ if err := p.ApplyPatches(false); err != nil {
+ if err := c.GenericMerge("rebase", "abort"); err != nil {
+ return err
+ }
+ return err
+ }
+
+ head_message, _ := c.GetHeadCommitMessage()
+ new_message := fmt.Sprintf("Split from \"%s\"", head_message)
+ _, err := c.Commit(new_message, "")
+ if err != nil {
+ return err
+ }
+
+ if c.onSuccessfulContinue != nil {
+ return errors.New("You are midway through another rebase operation. Please abort to start again")
+ }
+
+ c.PatchManager.Reset()
+ return c.GenericMerge("rebase", "continue")
+}