summaryrefslogtreecommitdiffstats
path: root/pkg/commands/git_commands/stash.go
diff options
context:
space:
mode:
authorAndrew Hynes <andrewjhynes@gmail.com>2022-11-01 16:08:34 -0230
committerGitHub <noreply@github.com>2022-11-01 16:08:34 -0230
commita47e72892aa9ea5860869a914905cae76d3bd94e (patch)
treeed837c4d62b825cdd1aa6667baf957258b603bd4 /pkg/commands/git_commands/stash.go
parent69040f094d2fb0b31c902ff4911296960db672c3 (diff)
parentc4e71356bbb0bff7ba4d12d4b86f2959f32fed47 (diff)
Merge branch 'master' into stash-untracked-changes
Diffstat (limited to 'pkg/commands/git_commands/stash.go')
-rw-r--r--pkg/commands/git_commands/stash.go31
1 files changed, 31 insertions, 0 deletions
diff --git a/pkg/commands/git_commands/stash.go b/pkg/commands/git_commands/stash.go
index 40e205a67..85056cd5c 100644
--- a/pkg/commands/git_commands/stash.go
+++ b/pkg/commands/git_commands/stash.go
@@ -2,6 +2,7 @@ package git_commands
import (
"fmt"
+ "strings"
"github.com/jesseduffield/lazygit/pkg/commands/loaders"
"github.com/jesseduffield/lazygit/pkg/commands/oscommands"
@@ -46,6 +47,19 @@ func (self *StashCommands) Save(message string) error {
return self.cmd.New("git stash save " + self.cmd.Quote(message)).Run()
}
+func (self *StashCommands) Store(sha string, message string) error {
+ trimmedMessage := strings.Trim(message, " \t")
+ if len(trimmedMessage) > 0 {
+ return self.cmd.New(fmt.Sprintf("git stash store %s -m %s", self.cmd.Quote(sha), self.cmd.Quote(trimmedMessage))).Run()
+ }
+ return self.cmd.New(fmt.Sprintf("git stash store %s", self.cmd.Quote(sha))).Run()
+}
+
+func (self *StashCommands) Sha(index int) (string, error) {
+ sha, _, err := self.cmd.New(fmt.Sprintf("git rev-parse refs/stash@{%d}", index)).DontLog().RunWithOutputs()
+ return strings.Trim(sha, "\r\n"), err
+}
+
func (self *StashCommands) ShowStashEntryCmdObj(index int) oscommands.ICmdObj {
cmdStr := fmt.Sprintf("git stash show -p --stat --color=%s --unified=%d stash@{%d}", self.UserConfig.Git.Paging.ColorArg, self.UserConfig.Git.DiffContextSize, index)
@@ -114,3 +128,20 @@ func (self *StashCommands) StashIncludeUntrackedChanges(message string) error {
return self.cmd.New(fmt.Sprintf("git stash save %s --include-untracked", self.cmd.Quote(message))).Run()
}
+func (self *StashCommands) Rename(index int, message string) error {
+ sha, err := self.Sha(index)
+ if err != nil {
+ return err
+ }
+
+ if err := self.Drop(index); err != nil {
+ return err
+ }
+
+ err = self.Store(sha, message)
+ if err != nil {
+ return err
+ }
+
+ return nil
+}