diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2020-03-28 12:43:31 +1100 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2020-03-28 13:19:35 +1100 |
commit | 0c0231c3e835ef93a7fe06a95c28bd00f1da6631 (patch) | |
tree | 50bc70e0a508888b9c370e4cbb0fe82f72dfdc44 /pkg/commands | |
parent | a9559a5c8738d6938f8750f0729f077e0842800e (diff) |
autostash changes when pulling file into index
Diffstat (limited to 'pkg/commands')
-rw-r--r-- | pkg/commands/patch_rebases.go | 26 |
1 files changed, 21 insertions, 5 deletions
diff --git a/pkg/commands/patch_rebases.go b/pkg/commands/patch_rebases.go index 19116e071..eeeb0876c 100644 --- a/pkg/commands/patch_rebases.go +++ b/pkg/commands/patch_rebases.go @@ -131,14 +131,22 @@ func (c *GitCommand) MovePatchToSelectedCommit(commits []*Commit, sourceCommitId return c.GenericMerge("rebase", "continue") } -func (c *GitCommand) PullPatchIntoIndex(commits []*Commit, commitIdx int, p *PatchManager) error { +func (c *GitCommand) PullPatchIntoIndex(commits []*Commit, commitIdx int, p *PatchManager, stash bool) error { + if stash { + if err := c.StashSave(c.Tr.SLocalize("StashPrefix") + commits[commitIdx].Sha); err != nil { + return err + } + } + 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 + if c.WorkingTreeState() == "rebasing" { + if err := c.GenericMerge("rebase", "abort"); err != nil { + return err + } } return err } @@ -155,12 +163,20 @@ func (c *GitCommand) PullPatchIntoIndex(commits []*Commit, commitIdx int, p *Pat c.onSuccessfulContinue = func() error { // add patches to index if err := p.ApplyPatches(false); err != nil { - if err := c.GenericMerge("rebase", "abort"); err != nil { - return err + if c.WorkingTreeState() == "rebasing" { + if err := c.GenericMerge("rebase", "abort"); err != nil { + return err + } } return err } + if stash { + if err := c.StashDo(0, "apply"); err != nil { + return err + } + } + c.PatchManager.Reset() return nil } |