1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-08-06 22:33:07 +02:00

Make stash loading work in filtering mode

This broke with the introduction of the age in the stashes list in bc330b8ff3
(which was included in 0.41, so 12 minor versions ago).

This makes it work again when filtering by file, but it still doesn't work when
filtering by folder (and never has). We'll fix that next.
This commit is contained in:
Stefan Haller
2025-07-11 16:23:22 +02:00
parent 0dfa078653
commit 09cbaf2cba
2 changed files with 5 additions and 8 deletions

View File

@ -32,7 +32,7 @@ func (self *StashLoader) GetStashEntries(filterPath string) []*models.StashEntry
return self.getUnfilteredStashEntries()
}
cmdArgs := NewGitCmd("stash").Arg("list", "--name-only", "--pretty=%ct|%gs").ToArgv()
cmdArgs := NewGitCmd("stash").Arg("list", "--name-only", "--pretty=%gd:%ct|%gs").ToArgv()
rawString, err := self.cmd.New(cmdArgs).DontLog().RunWithOutput()
if err != nil {
return self.getUnfilteredStashEntries()
@ -41,19 +41,19 @@ func (self *StashLoader) GetStashEntries(filterPath string) []*models.StashEntry
var currentStashEntry *models.StashEntry
lines := utils.SplitLines(rawString)
isAStash := func(line string) bool { return strings.HasPrefix(line, "stash@{") }
re := regexp.MustCompile(`stash@\{(\d+)\}`)
re := regexp.MustCompile(`^stash@\{(\d+)\}:(.*)$`)
outer:
for i := 0; i < len(lines); i++ {
if !isAStash(lines[i]) {
match := re.FindStringSubmatch(lines[i])
if match == nil {
continue
}
match := re.FindStringSubmatch(lines[i])
idx, err := strconv.Atoi(match[1])
if err != nil {
return self.getUnfilteredStashEntries()
}
currentStashEntry = stashEntryFromLine(lines[i], idx)
currentStashEntry = stashEntryFromLine(match[2], idx)
for i+1 < len(lines) && !isAStash(lines[i+1]) {
i++
if lines[i] == filterPath {

View File

@ -44,13 +44,10 @@ var FilterByPath = NewIntegrationTest(NewIntegrationTestArgs{
filterBy("file1")
t.Views().Stash().
/* EXPECTED:
Lines(
Contains("file1 again"),
Contains("file1"),
)
ACTUAL: */
IsEmpty()
t.GlobalPress(keys.Universal.Return)
filterBy("subdir")