mirror of
https://github.com/jesseduffield/lazygit.git
synced 2024-12-02 09:21:40 +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()
|
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()
|
rawString, err := self.cmd.New(cmdArgs).DontLog().RunWithOutput()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return self.getUnfilteredStashEntries()
|
return self.getUnfilteredStashEntries()
|
||||||
}
|
}
|
||||||
stashEntries := []*models.StashEntry{}
|
stashEntries := []*models.StashEntry{}
|
||||||
var currentStashEntry *models.StashEntry
|
var currentStashEntry *models.StashEntry
|
||||||
lines := utils.SplitLines(rawString)
|
lines := utils.SplitNul(rawString)
|
||||||
isAStash := func(line string) bool { return strings.HasPrefix(line, "stash@{") }
|
isAStash := func(line string) bool { return strings.HasPrefix(line, "stash@{") }
|
||||||
re := regexp.MustCompile(`stash@\{(\d+)\}`)
|
re := regexp.MustCompile(`stash@\{(\d+)\}`)
|
||||||
|
|
||||||
@ -66,7 +66,7 @@ outer:
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (self *StashLoader) getUnfilteredStashEntries() []*models.StashEntry {
|
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()
|
rawString, _ := self.cmd.New(cmdArgs).DontLog().RunWithOutput()
|
||||||
return lo.Map(utils.SplitNul(rawString), func(line string, index int) *models.StashEntry {
|
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 {
|
func (c *StashLoader) stashEntryFromLine(line string, index int) *models.StashEntry {
|
||||||
return &models.StashEntry{
|
model := &models.StashEntry{
|
||||||
Name: line,
|
Name: line,
|
||||||
Index: index,
|
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",
|
"No stash entries found",
|
||||||
"",
|
"",
|
||||||
oscommands.NewFakeRunner(t).
|
oscommands.NewFakeRunner(t).
|
||||||
ExpectGitArgs([]string{"stash", "list", "-z", "--pretty=%gs"}, "", nil),
|
ExpectGitArgs([]string{"stash", "list", "-z", "--pretty=%ct|%gs"}, "", nil),
|
||||||
[]*models.StashEntry{},
|
[]*models.StashEntry{},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"Several stash entries found",
|
"Several stash entries found",
|
||||||
"",
|
"",
|
||||||
oscommands.NewFakeRunner(t).
|
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",
|
"WIP on add-pkg-commands-test: 55c6af2 increase parallel build\x00WIP on master: bb86a3f update github template\x00",
|
||||||
nil,
|
nil,
|
||||||
),
|
),
|
||||||
|
@ -5,6 +5,7 @@ import "fmt"
|
|||||||
// StashEntry : A git stash entry
|
// StashEntry : A git stash entry
|
||||||
type StashEntry struct {
|
type StashEntry struct {
|
||||||
Index int
|
Index int
|
||||||
|
Recency string
|
||||||
Name string
|
Name string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@ package presentation
|
|||||||
import (
|
import (
|
||||||
"github.com/jesseduffield/lazygit/pkg/commands/models"
|
"github.com/jesseduffield/lazygit/pkg/commands/models"
|
||||||
"github.com/jesseduffield/lazygit/pkg/gui/presentation/icons"
|
"github.com/jesseduffield/lazygit/pkg/gui/presentation/icons"
|
||||||
|
"github.com/jesseduffield/lazygit/pkg/gui/style"
|
||||||
"github.com/jesseduffield/lazygit/pkg/theme"
|
"github.com/jesseduffield/lazygit/pkg/theme"
|
||||||
"github.com/samber/lo"
|
"github.com/samber/lo"
|
||||||
)
|
)
|
||||||
@ -21,10 +22,13 @@ func getStashEntryDisplayStrings(s *models.StashEntry, diffed bool) []string {
|
|||||||
textStyle = theme.DiffTerminalColor
|
textStyle = theme.DiffTerminalColor
|
||||||
}
|
}
|
||||||
|
|
||||||
res := make([]string, 0, 2)
|
res := make([]string, 0, 3)
|
||||||
|
res = append(res, style.FgCyan.Sprint(s.Recency))
|
||||||
|
|
||||||
if icons.IsIconEnabled() {
|
if icons.IsIconEnabled() {
|
||||||
res = append(res, textStyle.Sprint(icons.IconForStash(s)))
|
res = append(res, textStyle.Sprint(icons.IconForStash(s)))
|
||||||
}
|
}
|
||||||
|
|
||||||
res = append(res, textStyle.Sprint(s.Name))
|
res = append(res, textStyle.Sprint(s.Name))
|
||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
@ -22,14 +22,14 @@ var Rename = NewIntegrationTest(NewIntegrationTestArgs{
|
|||||||
t.Views().Stash().
|
t.Views().Stash().
|
||||||
Focus().
|
Focus().
|
||||||
Lines(
|
Lines(
|
||||||
Equals("On master: bar"),
|
Contains("On master: bar"),
|
||||||
Equals("On master: foo"),
|
Contains("On master: foo"),
|
||||||
).
|
).
|
||||||
SelectNextItem().
|
SelectNextItem().
|
||||||
Press(keys.Stash.RenameStash).
|
Press(keys.Stash.RenameStash).
|
||||||
Tap(func() {
|
Tap(func() {
|
||||||
t.ExpectPopup().Prompt().Title(Equals("Rename stash: stash@{1}")).Type(" baz").Confirm()
|
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().
|
t.Views().Stash().
|
||||||
Lines(
|
Lines(
|
||||||
Contains("my stashed file"),
|
MatchesRegexp(`\ds .* my stashed file`),
|
||||||
)
|
)
|
||||||
|
|
||||||
t.Views().Files().
|
t.Views().Files().
|
||||||
|
Loading…
Reference in New Issue
Block a user