Skip to content

Commit ee81a8e

Browse files
committed
Add hash field to models.StashEntry
1 parent 61d5b16 commit ee81a8e

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

pkg/commands/git_commands/stash_loader.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func (self *StashLoader) GetStashEntries(filterPath string) []*models.StashEntry
3232
return self.getUnfilteredStashEntries()
3333
}
3434

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

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

7171
rawString, _ := self.cmd.New(cmdArgs).DontLog().RunWithOutput()
7272
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 {
8080
Index: index,
8181
}
8282

83+
hash, line, ok := strings.Cut(line, "|")
84+
if !ok {
85+
return model
86+
}
87+
model.Hash = hash
88+
8389
tstr, msg, ok := strings.Cut(line, "|")
8490
if !ok {
8591
return model

pkg/commands/git_commands/stash_loader_test.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,15 @@ func TestGetStashEntries(t *testing.T) {
2727
"No stash entries found",
2828
"",
2929
oscommands.NewFakeRunner(t).
30-
ExpectGitArgs([]string{"stash", "list", "-z", "--pretty=%ct|%gs"}, "", nil),
30+
ExpectGitArgs([]string{"stash", "list", "-z", "--pretty=%H|%ct|%gs"}, "", nil),
3131
[]*models.StashEntry{},
3232
},
3333
{
3434
"Several stash entries found",
3535
"",
3636
oscommands.NewFakeRunner(t).
37-
ExpectGitArgs([]string{"stash", "list", "-z", "--pretty=%ct|%gs"},
38-
fmt.Sprintf("%d|WIP on add-pkg-commands-test: 55c6af2 increase parallel build\x00%d|WIP on master: bb86a3f update github template\x00",
37+
ExpectGitArgs([]string{"stash", "list", "-z", "--pretty=%H|%ct|%gs"},
38+
fmt.Sprintf("fa1afe1|%d|WIP on add-pkg-commands-test: 55c6af2 increase parallel build\x00deadbeef|%d|WIP on master: bb86a3f update github template\x00",
3939
hoursAgo,
4040
daysAgo,
4141
), nil),
@@ -44,11 +44,13 @@ func TestGetStashEntries(t *testing.T) {
4444
Index: 0,
4545
Name: "WIP on add-pkg-commands-test: 55c6af2 increase parallel build",
4646
Recency: "3h",
47+
Hash: "fa1afe1",
4748
},
4849
{
4950
Index: 1,
5051
Name: "WIP on master: bb86a3f update github template",
5152
Recency: "3d",
53+
Hash: "deadbeef",
5254
},
5355
},
5456
},

pkg/commands/models/stash_entry.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ type StashEntry struct {
77
Index int
88
Recency string
99
Name string
10+
Hash string
1011
}
1112

1213
func (s *StashEntry) FullRefName() string {

0 commit comments

Comments
 (0)