mirror of
https://github.com/jesseduffield/lazygit.git
synced 2024-11-30 09:16:47 +02:00
Add age to stash entries (#3174)
This commit is contained in:
commit
470632b97a
@ -32,14 +32,14 @@ func (self *StashLoader) GetStashEntries(filterPath string) []*models.StashEntry
|
||||
return self.getUnfilteredStashEntries()
|
||||
}
|
||||
|
||||
cmdArgs := NewGitCmd("stash").Arg("list", "--name-only").ToArgv()
|
||||
cmdArgs := NewGitCmd("stash").Arg("list", "-z", "--name-only", "--pretty=%ct|%gs").ToArgv()
|
||||
rawString, err := self.cmd.New(cmdArgs).DontLog().RunWithOutput()
|
||||
if err != nil {
|
||||
return self.getUnfilteredStashEntries()
|
||||
}
|
||||
stashEntries := []*models.StashEntry{}
|
||||
var currentStashEntry *models.StashEntry
|
||||
lines := utils.SplitLines(rawString)
|
||||
lines := utils.SplitNul(rawString)
|
||||
isAStash := func(line string) bool { return strings.HasPrefix(line, "stash@{") }
|
||||
re := regexp.MustCompile(`stash@\{(\d+)\}`)
|
||||
|
||||
@ -66,7 +66,7 @@ outer:
|
||||
}
|
||||
|
||||
func (self *StashLoader) getUnfilteredStashEntries() []*models.StashEntry {
|
||||
cmdArgs := NewGitCmd("stash").Arg("list", "-z", "--pretty=%gs").ToArgv()
|
||||
cmdArgs := NewGitCmd("stash").Arg("list", "-z", "--pretty=%ct|%gs").ToArgv()
|
||||
|
||||
rawString, _ := self.cmd.New(cmdArgs).DontLog().RunWithOutput()
|
||||
return lo.Map(utils.SplitNul(rawString), func(line string, index int) *models.StashEntry {
|
||||
@ -75,8 +75,23 @@ func (self *StashLoader) getUnfilteredStashEntries() []*models.StashEntry {
|
||||
}
|
||||
|
||||
func (c *StashLoader) stashEntryFromLine(line string, index int) *models.StashEntry {
|
||||
return &models.StashEntry{
|
||||
model := &models.StashEntry{
|
||||
Name: line,
|
||||
Index: index,
|
||||
}
|
||||
|
||||
tstr, msg, ok := strings.Cut(line, "|")
|
||||
if !ok {
|
||||
return model
|
||||
}
|
||||
|
||||
t, err := strconv.ParseInt(tstr, 10, 64)
|
||||
if err != nil {
|
||||
return model
|
||||
}
|
||||
|
||||
model.Name = msg
|
||||
model.Recency = utils.UnixToTimeAgo(t)
|
||||
|
||||
return model
|
||||
}
|
||||
|
@ -22,14 +22,14 @@ func TestGetStashEntries(t *testing.T) {
|
||||
"No stash entries found",
|
||||
"",
|
||||
oscommands.NewFakeRunner(t).
|
||||
ExpectGitArgs([]string{"stash", "list", "-z", "--pretty=%gs"}, "", nil),
|
||||
ExpectGitArgs([]string{"stash", "list", "-z", "--pretty=%ct|%gs"}, "", nil),
|
||||
[]*models.StashEntry{},
|
||||
},
|
||||
{
|
||||
"Several stash entries found",
|
||||
"",
|
||||
oscommands.NewFakeRunner(t).
|
||||
ExpectGitArgs([]string{"stash", "list", "-z", "--pretty=%gs"},
|
||||
ExpectGitArgs([]string{"stash", "list", "-z", "--pretty=%ct|%gs"},
|
||||
"WIP on add-pkg-commands-test: 55c6af2 increase parallel build\x00WIP on master: bb86a3f update github template\x00",
|
||||
nil,
|
||||
),
|
||||
|
@ -4,8 +4,9 @@ import "fmt"
|
||||
|
||||
// StashEntry : A git stash entry
|
||||
type StashEntry struct {
|
||||
Index int
|
||||
Name string
|
||||
Index int
|
||||
Recency string
|
||||
Name string
|
||||
}
|
||||
|
||||
func (s *StashEntry) FullRefName() string {
|
||||
|
@ -3,6 +3,7 @@ package presentation
|
||||
import (
|
||||
"github.com/jesseduffield/lazygit/pkg/commands/models"
|
||||
"github.com/jesseduffield/lazygit/pkg/gui/presentation/icons"
|
||||
"github.com/jesseduffield/lazygit/pkg/gui/style"
|
||||
"github.com/jesseduffield/lazygit/pkg/theme"
|
||||
"github.com/samber/lo"
|
||||
)
|
||||
@ -21,10 +22,13 @@ func getStashEntryDisplayStrings(s *models.StashEntry, diffed bool) []string {
|
||||
textStyle = theme.DiffTerminalColor
|
||||
}
|
||||
|
||||
res := make([]string, 0, 2)
|
||||
res := make([]string, 0, 3)
|
||||
res = append(res, style.FgCyan.Sprint(s.Recency))
|
||||
|
||||
if icons.IsIconEnabled() {
|
||||
res = append(res, textStyle.Sprint(icons.IconForStash(s)))
|
||||
}
|
||||
|
||||
res = append(res, textStyle.Sprint(s.Name))
|
||||
return res
|
||||
}
|
||||
|
@ -22,14 +22,14 @@ var Rename = NewIntegrationTest(NewIntegrationTestArgs{
|
||||
t.Views().Stash().
|
||||
Focus().
|
||||
Lines(
|
||||
Equals("On master: bar"),
|
||||
Equals("On master: foo"),
|
||||
Contains("On master: bar"),
|
||||
Contains("On master: foo"),
|
||||
).
|
||||
SelectNextItem().
|
||||
Press(keys.Stash.RenameStash).
|
||||
Tap(func() {
|
||||
t.ExpectPopup().Prompt().Title(Equals("Rename stash: stash@{1}")).Type(" baz").Confirm()
|
||||
}).
|
||||
SelectedLine(Equals("On master: foo baz"))
|
||||
SelectedLine(Contains("On master: foo baz"))
|
||||
},
|
||||
})
|
||||
|
@ -29,7 +29,7 @@ var Stash = NewIntegrationTest(NewIntegrationTestArgs{
|
||||
|
||||
t.Views().Stash().
|
||||
Lines(
|
||||
Contains("my stashed file"),
|
||||
MatchesRegexp(`\ds .* my stashed file`),
|
||||
)
|
||||
|
||||
t.Views().Files().
|
||||
|
Loading…
Reference in New Issue
Block a user