From 09cbaf2cba13536d08428d8eb3f6d747f5af7891 Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Fri, 11 Jul 2025 16:23:22 +0200 Subject: [PATCH] Make stash loading work in filtering mode This broke with the introduction of the age in the stashes list in bc330b8ff3ef (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. --- pkg/commands/git_commands/stash_loader.go | 10 +++++----- pkg/integration/tests/stash/filter_by_path.go | 3 --- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/pkg/commands/git_commands/stash_loader.go b/pkg/commands/git_commands/stash_loader.go index 5ec5d4ed4..243be807d 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=%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 { diff --git a/pkg/integration/tests/stash/filter_by_path.go b/pkg/integration/tests/stash/filter_by_path.go index 8f151134b..7881e9225 100644 --- a/pkg/integration/tests/stash/filter_by_path.go +++ b/pkg/integration/tests/stash/filter_by_path.go @@ -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")