diff options
author | DerTeta <derteta@gmx.de> | 2021-09-11 00:47:50 +0200 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2021-12-06 22:37:28 +1100 |
commit | c99d373e133d96927ef14700ba8d53365eeffcda (patch) | |
tree | 2b706eaf94fea3c743fe17a4a3c923ee974e3426 /pkg | |
parent | ecfafb6fbece9491fbece40286889e625c247745 (diff) |
Use `DiffContextSize` in `ShowStashEntryCmdStr`
Diffstat (limited to 'pkg')
-rw-r--r-- | pkg/commands/stash_entries.go | 2 | ||||
-rw-r--r-- | pkg/commands/stash_entries_test.go | 34 |
2 files changed, 35 insertions, 1 deletions
diff --git a/pkg/commands/stash_entries.go b/pkg/commands/stash_entries.go index 2707903d7..9c56c78dc 100644 --- a/pkg/commands/stash_entries.go +++ b/pkg/commands/stash_entries.go @@ -15,7 +15,7 @@ func (c *GitCommand) StashSave(message string) error { // GetStashEntryDiff stash diff func (c *GitCommand) ShowStashEntryCmdStr(index int) string { - return fmt.Sprintf("git stash show -p --stat --color=%s stash@{%d}", c.colorArg(), index) + return fmt.Sprintf("git stash show -p --stat --color=%s --unified=%d stash@{%d}", c.colorArg(), c.Config.GetUserConfig().Git.DiffContextSize, index) } // StashSaveStagedChanges stashes only the currently staged changes. This takes a few steps diff --git a/pkg/commands/stash_entries_test.go b/pkg/commands/stash_entries_test.go index bb4778dc6..29a9dc36f 100644 --- a/pkg/commands/stash_entries_test.go +++ b/pkg/commands/stash_entries_test.go @@ -33,3 +33,37 @@ func TestGitCommandStashSave(t *testing.T) { assert.NoError(t, gitCmd.StashSave("A stash message")) } + +// TestGitCommandShowStashEntryCmdStr is a function. +func TestGitCommandShowStashEntryCmdStr(t *testing.T) { + type scenario struct { + testName string + index int + contextSize int + expected string + } + + scenarios := []scenario{ + { + testName: "Default case", + index: 5, + contextSize: 3, + expected: "git stash show -p --stat --color=always --unified=3 stash@{5}", + }, + { + testName: "Show diff with custom context size", + index: 5, + contextSize: 77, + expected: "git stash show -p --stat --color=always --unified=77 stash@{5}", + }, + } + + for _, s := range scenarios { + t.Run(s.testName, func(t *testing.T) { + gitCmd := NewDummyGitCommand() + gitCmd.Config.GetUserConfig().Git.DiffContextSize = s.contextSize + cmdStr := gitCmd.ShowStashEntryCmdStr(s.index) + assert.Equal(t, s.expected, cmdStr) + }) + } +} |