Skip to content

Commit 6cb5e62

Browse files
Merge pull request jesseduffield#2218 from Ryooooooga/feature/empty-stash-message
2 parents fc0b14e + a4239c7 commit 6cb5e62

File tree

4 files changed

+44
-5
lines changed

4 files changed

+44
-5
lines changed

pkg/commands/loaders/stash.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ outer:
6565
}
6666

6767
func (self *StashLoader) getUnfilteredStashEntries() []*models.StashEntry {
68-
rawString, _ := self.cmd.New("git stash list --pretty='%gs'").DontLog().RunWithOutput()
69-
return slices.MapWithIndex(utils.SplitLines(rawString), func(line string, index int) *models.StashEntry {
68+
rawString, _ := self.cmd.New("git stash list -z --pretty='%gs'").DontLog().RunWithOutput()
69+
return slices.MapWithIndex(utils.SplitNul(rawString), func(line string, index int) *models.StashEntry {
7070
return self.stashEntryFromLine(line, index)
7171
})
7272
}

pkg/commands/loaders/stash_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,16 @@ func TestGetStashEntries(t *testing.T) {
2222
"No stash entries found",
2323
"",
2424
oscommands.NewFakeRunner(t).
25-
Expect(`git stash list --pretty='%gs'`, "", nil),
25+
Expect(`git stash list -z --pretty='%gs'`, "", nil),
2626
[]*models.StashEntry{},
2727
},
2828
{
2929
"Several stash entries found",
3030
"",
3131
oscommands.NewFakeRunner(t).
3232
Expect(
33-
`git stash list --pretty='%gs'`,
34-
"WIP on add-pkg-commands-test: 55c6af2 increase parallel build\nWIP on master: bb86a3f update github template",
33+
`git stash list -z --pretty='%gs'`,
34+
"WIP on add-pkg-commands-test: 55c6af2 increase parallel build\x00WIP on master: bb86a3f update github template\x00",
3535
nil,
3636
),
3737
[]*models.StashEntry{

pkg/utils/lines.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@ func SplitLines(multilineString string) []string {
1717
return lines
1818
}
1919

20+
func SplitNul(str string) []string {
21+
if str == "" {
22+
return make([]string, 0)
23+
}
24+
str = strings.TrimSuffix(str, "\x00")
25+
return strings.Split(str, "\x00")
26+
}
27+
2028
// NormalizeLinefeeds - Removes all Windows and Mac style line feeds
2129
func NormalizeLinefeeds(str string) string {
2230
str = strings.Replace(str, "\r\n", "\n", -1)

pkg/utils/lines_test.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,37 @@ func TestSplitLines(t *testing.T) {
3636
}
3737
}
3838

39+
func TestSplitNul(t *testing.T) {
40+
type scenario struct {
41+
multilineString string
42+
expected []string
43+
}
44+
45+
scenarios := []scenario{
46+
{
47+
"",
48+
[]string{},
49+
},
50+
{
51+
"\x00",
52+
[]string{
53+
"",
54+
},
55+
},
56+
{
57+
"hello world !\x00hello universe !\x00",
58+
[]string{
59+
"hello world !",
60+
"hello universe !",
61+
},
62+
},
63+
}
64+
65+
for _, s := range scenarios {
66+
assert.EqualValues(t, s.expected, SplitNul(s.multilineString))
67+
}
68+
}
69+
3970
// TestNormalizeLinefeeds is a function.
4071
func TestNormalizeLinefeeds(t *testing.T) {
4172
type scenario struct {

0 commit comments

Comments
 (0)