diff options
author | Ryooooooga <eial5q265e5@gmail.com> | 2022-10-15 11:15:31 +0900 |
---|---|---|
committer | Ryooooooga <eial5q265e5@gmail.com> | 2022-10-16 09:12:43 +0900 |
commit | eceb3a5aa6de864f31c52016e6fd497b9b6a1214 (patch) | |
tree | a2240f25bf60b1d4277ee85e9c5603f05a3ed6aa /pkg/commands/git_commands/stash.go | |
parent | 8a9eefa4d275f925e149be2c05c5c6958da86f5b (diff) |
chore: refactor rename stash
Diffstat (limited to 'pkg/commands/git_commands/stash.go')
-rw-r--r-- | pkg/commands/git_commands/stash.go | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/pkg/commands/git_commands/stash.go b/pkg/commands/git_commands/stash.go index 841765e81..176a67e52 100644 --- a/pkg/commands/git_commands/stash.go +++ b/pkg/commands/git_commands/stash.go @@ -1,7 +1,9 @@ package git_commands import ( + "errors" "fmt" + "regexp" "strings" "github.com/jesseduffield/lazygit/pkg/commands/loaders" @@ -119,3 +121,26 @@ func (self *StashCommands) SaveStagedChanges(message string) error { return nil } + +func (self *StashCommands) Rename(index int, message string) error { + output, err := self.Drop(index) + if err != nil { + return err + } + + // `output` is in the following format: + // Dropped refs/stash@{0} (f0d0f20f2f61ffd6d6bfe0752deffa38845a3edd) + stashShaPattern := regexp.MustCompile(`\(([0-9a-f]+)\)`) + matches := stashShaPattern.FindStringSubmatch(output) + if len(matches) <= 1 { + return errors.New("Output of `git stash drop` is invalid") // Usually this error does not occur + } + stashSha := matches[1] + + err = self.Store(stashSha, message) + if err != nil { + return err + } + + return nil +} |