1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-07-30 03:23:08 +03:00

fix: fix stash with empty message

This commit is contained in:
Ryooooooga
2022-10-13 22:20:15 +09:00
parent fc0b14edef
commit a4239c7a37
4 changed files with 44 additions and 5 deletions

View File

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

View File

@ -22,7 +22,7 @@ func TestGetStashEntries(t *testing.T) {
"No stash entries found", "No stash entries found",
"", "",
oscommands.NewFakeRunner(t). oscommands.NewFakeRunner(t).
Expect(`git stash list --pretty='%gs'`, "", nil), Expect(`git stash list -z --pretty='%gs'`, "", nil),
[]*models.StashEntry{}, []*models.StashEntry{},
}, },
{ {
@ -30,8 +30,8 @@ func TestGetStashEntries(t *testing.T) {
"", "",
oscommands.NewFakeRunner(t). oscommands.NewFakeRunner(t).
Expect( Expect(
`git stash list --pretty='%gs'`, `git stash list -z --pretty='%gs'`,
"WIP on add-pkg-commands-test: 55c6af2 increase parallel build\nWIP on master: bb86a3f update github template", "WIP on add-pkg-commands-test: 55c6af2 increase parallel build\x00WIP on master: bb86a3f update github template\x00",
nil, nil,
), ),
[]*models.StashEntry{ []*models.StashEntry{

View File

@ -17,6 +17,14 @@ func SplitLines(multilineString string) []string {
return lines return lines
} }
func SplitNul(str string) []string {
if str == "" {
return make([]string, 0)
}
str = strings.TrimSuffix(str, "\x00")
return strings.Split(str, "\x00")
}
// NormalizeLinefeeds - Removes all Windows and Mac style line feeds // NormalizeLinefeeds - Removes all Windows and Mac style line feeds
func NormalizeLinefeeds(str string) string { func NormalizeLinefeeds(str string) string {
str = strings.Replace(str, "\r\n", "\n", -1) str = strings.Replace(str, "\r\n", "\n", -1)

View File

@ -36,6 +36,37 @@ func TestSplitLines(t *testing.T) {
} }
} }
func TestSplitNul(t *testing.T) {
type scenario struct {
multilineString string
expected []string
}
scenarios := []scenario{
{
"",
[]string{},
},
{
"\x00",
[]string{
"",
},
},
{
"hello world !\x00hello universe !\x00",
[]string{
"hello world !",
"hello universe !",
},
},
}
for _, s := range scenarios {
assert.EqualValues(t, s.expected, SplitNul(s.multilineString))
}
}
// TestNormalizeLinefeeds is a function. // TestNormalizeLinefeeds is a function.
func TestNormalizeLinefeeds(t *testing.T) { func TestNormalizeLinefeeds(t *testing.T) {
type scenario struct { type scenario struct {