Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions pkg/commands/git_commands/stash_loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func (self *StashLoader) GetStashEntries(filterPath string) []*models.StashEntry
return self.getUnfilteredStashEntries()
}

cmdArgs := NewGitCmd("stash").Arg("list", "--name-only", "--pretty=%gd:%ct|%gs").ToArgv()
cmdArgs := NewGitCmd("stash").Arg("list", "--name-only", "--pretty=%gd:%H|%ct|%gs").ToArgv()
rawString, err := self.cmd.New(cmdArgs).DontLog().RunWithOutput()
if err != nil {
return self.getUnfilteredStashEntries()
Expand Down Expand Up @@ -66,7 +66,7 @@ outer:
}

func (self *StashLoader) getUnfilteredStashEntries() []*models.StashEntry {
cmdArgs := NewGitCmd("stash").Arg("list", "-z", "--pretty=%ct|%gs").ToArgv()
cmdArgs := NewGitCmd("stash").Arg("list", "-z", "--pretty=%H|%ct|%gs").ToArgv()

rawString, _ := self.cmd.New(cmdArgs).DontLog().RunWithOutput()
return lo.Map(utils.SplitNul(rawString), func(line string, index int) *models.StashEntry {
Expand All @@ -80,6 +80,12 @@ func stashEntryFromLine(line string, index int) *models.StashEntry {
Index: index,
}

hash, line, ok := strings.Cut(line, "|")
if !ok {
return model
}
model.Hash = hash

tstr, msg, ok := strings.Cut(line, "|")
if !ok {
return model
Expand Down
28 changes: 19 additions & 9 deletions pkg/commands/git_commands/stash_loader_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package git_commands

import (
"fmt"
"testing"
"time"

"github.com/jesseduffield/lazygit/pkg/commands/models"
"github.com/jesseduffield/lazygit/pkg/commands/oscommands"
Expand All @@ -17,30 +19,38 @@ func TestGetStashEntries(t *testing.T) {
expectedStashEntries []*models.StashEntry
}

hoursAgo := time.Now().Unix() - 3*3600 - 1800
daysAgo := time.Now().Unix() - 3*3600*24 - 3600*12

scenarios := []scenario{
{
"No stash entries found",
"",
oscommands.NewFakeRunner(t).
ExpectGitArgs([]string{"stash", "list", "-z", "--pretty=%ct|%gs"}, "", nil),
ExpectGitArgs([]string{"stash", "list", "-z", "--pretty=%H|%ct|%gs"}, "", nil),
[]*models.StashEntry{},
},
{
"Several stash entries found",
"",
oscommands.NewFakeRunner(t).
ExpectGitArgs([]string{"stash", "list", "-z", "--pretty=%ct|%gs"},
"WIP on add-pkg-commands-test: 55c6af2 increase parallel build\x00WIP on master: bb86a3f update github template\x00",
nil,
),
ExpectGitArgs([]string{"stash", "list", "-z", "--pretty=%H|%ct|%gs"},
fmt.Sprintf("fa1afe1|%d|WIP on add-pkg-commands-test: 55c6af2 increase parallel build\x00deadbeef|%d|WIP on master: bb86a3f update github template\x00",
hoursAgo,
daysAgo,
), nil),
[]*models.StashEntry{
{
Index: 0,
Name: "WIP on add-pkg-commands-test: 55c6af2 increase parallel build",
Index: 0,
Name: "WIP on add-pkg-commands-test: 55c6af2 increase parallel build",
Recency: "3h",
Hash: "fa1afe1",
},
{
Index: 1,
Name: "WIP on master: bb86a3f update github template",
Index: 1,
Name: "WIP on master: bb86a3f update github template",
Recency: "3d",
Hash: "deadbeef",
},
},
},
Expand Down
1 change: 1 addition & 0 deletions pkg/commands/models/stash_entry.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ type StashEntry struct {
Index int
Recency string
Name string
Hash string
}

func (s *StashEntry) FullRefName() string {
Expand Down
8 changes: 5 additions & 3 deletions pkg/gui/controllers/stash_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func (self *StashController) handleStashApply(stashEntry *models.StashEntry) err
Title: self.c.Tr.StashApply,
Prompt: self.c.Tr.SureApplyStashEntry,
HandleConfirm: func() error {
self.c.LogAction(self.c.Tr.Actions.Stash)
self.c.LogAction(self.c.Tr.Actions.ApplyStash)
err := self.c.Git().Stash.Apply(stashEntry.Index)
self.postStashRefresh()
if err != nil {
Expand All @@ -128,7 +128,8 @@ func (self *StashController) handleStashApply(stashEntry *models.StashEntry) err

func (self *StashController) handleStashPop(stashEntry *models.StashEntry) error {
pop := func() error {
self.c.LogAction(self.c.Tr.Actions.Stash)
self.c.LogAction(self.c.Tr.Actions.PopStash)
self.c.LogCommand("Popping stash "+stashEntry.Hash, false)
err := self.c.Git().Stash.Pop(stashEntry.Index)
self.postStashRefresh()
if err != nil {
Expand Down Expand Up @@ -160,8 +161,9 @@ func (self *StashController) handleStashDrop(stashEntries []*models.StashEntry)
Title: self.c.Tr.StashDrop,
Prompt: self.c.Tr.SureDropStashEntry,
HandleConfirm: func() error {
self.c.LogAction(self.c.Tr.Actions.Stash)
self.c.LogAction(self.c.Tr.Actions.DropStash)
for i := len(stashEntries) - 1; i >= 0; i-- {
self.c.LogCommand("Dropping stash "+stashEntries[i].Hash, false)
err := self.c.Git().Stash.Drop(stashEntries[i].Index)
self.c.Refresh(types.RefreshOptions{Scope: []types.RefreshableView{types.STASH}})
if err != nil {
Expand Down
6 changes: 6 additions & 0 deletions pkg/i18n/english.go
Original file line number Diff line number Diff line change
Expand Up @@ -1011,6 +1011,9 @@ type Actions struct {
UpdateRemote string
ApplyPatch string
Stash string
PopStash string
ApplyStash string
DropStash string
RenameStash string
RemoveSubmodule string
ResetSubmodule string
Expand Down Expand Up @@ -2050,6 +2053,9 @@ func EnglishTranslationSet() *TranslationSet {
UpdateRemote: "Update remote",
ApplyPatch: "Apply patch",
Stash: "Stash",
PopStash: "Pop stash",
ApplyStash: "Apply stash",
DropStash: "Drop stash",
RenameStash: "Rename stash",
RemoveSubmodule: "Remove submodule",
ResetSubmodule: "Reset submodule",
Expand Down
Loading