summaryrefslogtreecommitdiffstats
path: root/pkg/commands/git_commands/stash.go
diff options
context:
space:
mode:
authorLuka Markušić <luka.markusic@microblink.com>2022-04-14 21:45:55 +0200
committerLuka Markušić <luka.markusic@microblink.com>2022-04-14 21:45:55 +0200
commit1ae2dc994102841a189c85ca4c61b88d7cf82724 (patch)
treef9ae2a729da5edfb1e009789604f3dc8916de93e /pkg/commands/git_commands/stash.go
parent6f7038c8277f82c32d2c23502f94fdf675ad07e1 (diff)
The four horsemen of stashing
Diffstat (limited to 'pkg/commands/git_commands/stash.go')
-rw-r--r--pkg/commands/git_commands/stash.go14
1 files changed, 13 insertions, 1 deletions
diff --git a/pkg/commands/git_commands/stash.go b/pkg/commands/git_commands/stash.go
index 26460bfa0..71b8f655b 100644
--- a/pkg/commands/git_commands/stash.go
+++ b/pkg/commands/git_commands/stash.go
@@ -38,7 +38,6 @@ func (self *StashCommands) Apply(index int) error {
}
// Save save stash
-// TODO: before calling this, check if there is anything to save
func (self *StashCommands) Save(message string) error {
return self.cmd.New("git stash save " + self.cmd.Quote(message)).Run()
}
@@ -53,6 +52,19 @@ func (self *StashCommands) StashAndKeepIndex(message string) error {
return self.cmd.New(fmt.Sprintf("git stash save %s --keep-index", self.cmd.Quote(message))).Run()
}
+func (self *StashCommands) StashUnstagedChanges(message string) error {
+ if err := self.cmd.New("git commit -m \"WIP\"").Run(); err != nil {
+ return err
+ }
+ if err := self.Save(message); err != nil {
+ return err
+ }
+ if err := self.cmd.New("git reset --soft HEAD^").Run(); err != nil {
+ return err
+ }
+ return nil
+}
+
// SaveStagedChanges stashes only the currently staged changes. This takes a few steps
// shoutouts to Joe on https://stackoverflow.com/questions/14759748/stashing-only-staged-changes-in-git-is-it-possible
func (self *StashCommands) SaveStagedChanges(message string) error {