summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2023-05-19 19:34:29 +1000
committerStefan Haller <stefan@haller-berlin.de>2023-05-19 17:49:22 +0200
commitd161afe37f2ef29a2b322e21e4bee38f1ba66d7c (patch)
treee9d7cbeabc71369fb876d55d32502977700a030f
parent3dd96a8010a0b98c96a8ff690f0c5b63e9a682d5 (diff)
Support ignoring whitespace on stash
-rw-r--r--pkg/commands/git_commands/stash.go15
-rw-r--r--pkg/commands/git_commands/stash_test.go36
-rw-r--r--pkg/gui/controllers/stash_controller.go7
3 files changed, 42 insertions, 16 deletions
diff --git a/pkg/commands/git_commands/stash.go b/pkg/commands/git_commands/stash.go
index 572a87a73..54164e736 100644
--- a/pkg/commands/git_commands/stash.go
+++ b/pkg/commands/git_commands/stash.go
@@ -59,8 +59,19 @@ func (self *StashCommands) Sha(index int) (string, error) {
return strings.Trim(sha, "\r\n"), err
}
-func (self *StashCommands) ShowStashEntryCmdObj(index int) oscommands.ICmdObj {
- cmdStr := fmt.Sprintf("git stash show -p --stat --color=%s --unified=%d stash@{%d}", self.UserConfig.Git.Paging.ColorArg, self.UserConfig.Git.DiffContextSize, index)
+func (self *StashCommands) ShowStashEntryCmdObj(index int, ignoreWhitespace bool) oscommands.ICmdObj {
+ ignoreWhitespaceFlag := ""
+ if ignoreWhitespace {
+ ignoreWhitespaceFlag = " --ignore-all-space"
+ }
+
+ cmdStr := fmt.Sprintf(
+ "git stash show -p --stat --color=%s --unified=%d%s stash@{%d}",
+ self.UserConfig.Git.Paging.ColorArg,
+ self.UserConfig.Git.DiffContextSize,
+ ignoreWhitespaceFlag,
+ index,
+ )
return self.cmd.New(cmdStr).DontLog()
}
diff --git a/pkg/commands/git_commands/stash_test.go b/pkg/commands/git_commands/stash_test.go
index 1a4e50822..2fb03b90e 100644
--- a/pkg/commands/git_commands/stash_test.go
+++ b/pkg/commands/git_commands/stash_test.go
@@ -99,24 +99,34 @@ func TestStashSha(t *testing.T) {
func TestStashStashEntryCmdObj(t *testing.T) {
type scenario struct {
- testName string
- index int
- contextSize int
- expected string
+ testName string
+ index int
+ contextSize int
+ ignoreWhitespace bool
+ expected string
}
scenarios := []scenario{
{
- testName: "Default case",
- index: 5,
- contextSize: 3,
- expected: "git stash show -p --stat --color=always --unified=3 stash@{5}",
+ testName: "Default case",
+ index: 5,
+ contextSize: 3,
+ ignoreWhitespace: false,
+ expected: "git stash show -p --stat --color=always --unified=3 stash@{5}",
+ },
+ {
+ testName: "Show diff with custom context size",
+ index: 5,
+ contextSize: 77,
+ ignoreWhitespace: false,
+ expected: "git stash show -p --stat --color=always --unified=77 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}",
+ testName: "Default case",
+ index: 5,
+ contextSize: 3,
+ ignoreWhitespace: true,
+ expected: "git stash show -p --stat --color=always --unified=3 --ignore-all-space stash@{5}",
},
}
@@ -127,7 +137,7 @@ func TestStashStashEntryCmdObj(t *testing.T) {
userConfig.Git.DiffContextSize = s.contextSize
instance := buildStashCommands(commonDeps{userConfig: userConfig})
- cmdStr := instance.ShowStashEntryCmdObj(s.index).ToString()
+ cmdStr := instance.ShowStashEntryCmdObj(s.index, s.ignoreWhitespace).ToString()
assert.Equal(t, s.expected, cmdStr)
})
}
diff --git a/pkg/gui/controllers/stash_controller.go b/pkg/gui/controllers/stash_controller.go
index 4b5135884..e308abade 100644
--- a/pkg/gui/controllers/stash_controller.go
+++ b/pkg/gui/controllers/stash_controller.go
@@ -63,7 +63,12 @@ func (self *StashController) GetOnRenderToMain() func() error {
if stashEntry == nil {
task = types.NewRenderStringTask(self.c.Tr.NoStashEntries)
} else {
- task = types.NewRunPtyTask(self.c.Git().Stash.ShowStashEntryCmdObj(stashEntry.Index).GetCmd())
+ task = types.NewRunPtyTask(
+ self.c.Git().Stash.ShowStashEntryCmdObj(
+ stashEntry.Index,
+ self.c.State().GetIgnoreWhitespaceInDiffView(),
+ ).GetCmd(),
+ )
}
return self.c.RenderToMainViews(types.RefreshMainOpts{