From ee81a8e3c23ab7e7573d30f94b49a02235c4aa9b Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Mon, 25 Aug 2025 13:49:34 +0200 Subject: [PATCH] Add hash field to models.StashEntry --- pkg/commands/git_commands/stash_loader.go | 10 ++++++++-- pkg/commands/git_commands/stash_loader_test.go | 8 +++++--- pkg/commands/models/stash_entry.go | 1 + 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/pkg/commands/git_commands/stash_loader.go b/pkg/commands/git_commands/stash_loader.go index 67c3fb317..a1e16ae47 100644 --- a/pkg/commands/git_commands/stash_loader.go +++ b/pkg/commands/git_commands/stash_loader.go @@ -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() @@ -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 { @@ -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 diff --git a/pkg/commands/git_commands/stash_loader_test.go b/pkg/commands/git_commands/stash_loader_test.go index 3b0bf3eea..7ed000589 100644 --- a/pkg/commands/git_commands/stash_loader_test.go +++ b/pkg/commands/git_commands/stash_loader_test.go @@ -27,15 +27,15 @@ func TestGetStashEntries(t *testing.T) { "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"}, - fmt.Sprintf("%d|WIP on add-pkg-commands-test: 55c6af2 increase parallel build\x00%d|WIP on master: bb86a3f update github template\x00", + 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), @@ -44,11 +44,13 @@ func TestGetStashEntries(t *testing.T) { 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", Recency: "3d", + Hash: "deadbeef", }, }, }, diff --git a/pkg/commands/models/stash_entry.go b/pkg/commands/models/stash_entry.go index 92cb06a07..caf20b1d6 100644 --- a/pkg/commands/models/stash_entry.go +++ b/pkg/commands/models/stash_entry.go @@ -7,6 +7,7 @@ type StashEntry struct { Index int Recency string Name string + Hash string } func (s *StashEntry) FullRefName() string {