diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2020-09-29 18:46:45 +1000 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2020-09-29 20:48:49 +1000 |
commit | 91f0b0e28fb93bf715a4fda67fcbb400ffbc680b (patch) | |
tree | aa6e19417268c86129e967997582006bfb6f3784 /pkg/commands | |
parent | 8d2af5cc61c8bc94da6f608598ff27aead491c6a (diff) |
move stash panel
Diffstat (limited to 'pkg/commands')
-rw-r--r-- | pkg/commands/git.go | 14 | ||||
-rw-r--r-- | pkg/commands/git_test.go | 9 | ||||
-rw-r--r-- | pkg/commands/stash_entry.go | 21 |
3 files changed, 12 insertions, 32 deletions
diff --git a/pkg/commands/git.go b/pkg/commands/git.go index e7fcbd634..2d75330e6 100644 --- a/pkg/commands/git.go +++ b/pkg/commands/git.go @@ -200,10 +200,10 @@ func findDotGitDir(stat func(string) (os.FileInfo, error), readFile func(filenam return strings.TrimSpace(strings.TrimPrefix(fileContent, "gitdir: ")), nil } -func (c *GitCommand) getUnfilteredStashEntries() []*StashEntry { +func (c *GitCommand) getUnfilteredStashEntries() []*models.StashEntry { unescaped := "git stash list --pretty='%gs'" rawString, _ := c.OSCommand.RunCommandWithOutput(unescaped) - stashEntries := []*StashEntry{} + stashEntries := []*models.StashEntry{} for i, line := range utils.SplitLines(rawString) { stashEntries = append(stashEntries, stashEntryFromLine(line, i)) } @@ -211,7 +211,7 @@ func (c *GitCommand) getUnfilteredStashEntries() []*StashEntry { } // GetStashEntries stash entries -func (c *GitCommand) GetStashEntries(filterPath string) []*StashEntry { +func (c *GitCommand) GetStashEntries(filterPath string) []*models.StashEntry { if filterPath == "" { return c.getUnfilteredStashEntries() } @@ -221,8 +221,8 @@ func (c *GitCommand) GetStashEntries(filterPath string) []*StashEntry { if err != nil { return c.getUnfilteredStashEntries() } - stashEntries := []*StashEntry{} - var currentStashEntry *StashEntry + stashEntries := []*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+)\}`) @@ -249,8 +249,8 @@ outer: return stashEntries } -func stashEntryFromLine(line string, index int) *StashEntry { - return &StashEntry{ +func stashEntryFromLine(line string, index int) *models.StashEntry { + return &models.StashEntry{ Name: line, Index: index, } diff --git a/pkg/commands/git_test.go b/pkg/commands/git_test.go index e22750425..17f31e9cd 100644 --- a/pkg/commands/git_test.go +++ b/pkg/commands/git_test.go @@ -13,6 +13,7 @@ import ( "github.com/go-errors/errors" gogit "github.com/go-git/go-git/v5" "github.com/jesseduffield/lazygit/pkg/i18n" + "github.com/jesseduffield/lazygit/pkg/models" "github.com/jesseduffield/lazygit/pkg/test" "github.com/stretchr/testify/assert" ) @@ -260,7 +261,7 @@ func TestGitCommandGetStashEntries(t *testing.T) { type scenario struct { testName string command func(string, ...string) *exec.Cmd - test func([]*StashEntry) + test func([]*models.StashEntry) } scenarios := []scenario{ @@ -269,7 +270,7 @@ func TestGitCommandGetStashEntries(t *testing.T) { func(string, ...string) *exec.Cmd { return exec.Command("echo") }, - func(entries []*StashEntry) { + func(entries []*models.StashEntry) { assert.Len(t, entries, 0) }, }, @@ -278,8 +279,8 @@ func TestGitCommandGetStashEntries(t *testing.T) { func(string, ...string) *exec.Cmd { return exec.Command("echo", "WIP on add-pkg-commands-test: 55c6af2 increase parallel build\nWIP on master: bb86a3f update github template") }, - func(entries []*StashEntry) { - expected := []*StashEntry{ + func(entries []*models.StashEntry) { + expected := []*models.StashEntry{ { 0, "WIP on add-pkg-commands-test: 55c6af2 increase parallel build", diff --git a/pkg/commands/stash_entry.go b/pkg/commands/stash_entry.go deleted file mode 100644 index bdb899a75..000000000 --- a/pkg/commands/stash_entry.go +++ /dev/null @@ -1,21 +0,0 @@ -package commands - -import "fmt" - -// StashEntry : A git stash entry -type StashEntry struct { - Index int - Name string -} - -func (s *StashEntry) RefName() string { - return fmt.Sprintf("stash@{%d}", s.Index) -} - -func (s *StashEntry) ID() string { - return s.RefName() -} - -func (s *StashEntry) Description() string { - return s.RefName() + ": " + s.Name -} |