Skip to content

Commit 89d50fa

Browse files
committed
Use external diff command in stashes panel
This was forgotten in 6266e19.
1 parent 0f785c4 commit 89d50fa

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

pkg/commands/git_commands/stash.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,15 @@ func (self *StashCommands) Hash(index int) (string, error) {
8181
}
8282

8383
func (self *StashCommands) ShowStashEntryCmdObj(index int) *oscommands.CmdObj {
84+
extDiffCmd := self.UserConfig().Git.Paging.ExternalDiffCommand
85+
8486
// "-u" is the same as "--include-untracked", but the latter fails in older git versions for some reason
8587
cmdArgs := NewGitCmd("stash").Arg("show").
8688
Arg("-p").
8789
Arg("--stat").
8890
Arg("-u").
91+
ConfigIf(extDiffCmd != "", "diff.external="+extDiffCmd).
92+
ArgIfElse(extDiffCmd != "", "--ext-diff", "--no-ext-diff").
8993
Arg(fmt.Sprintf("--color=%s", self.UserConfig().Git.Paging.ColorArg)).
9094
Arg(fmt.Sprintf("--unified=%d", self.UserConfig().Git.DiffContextSize)).
9195
ArgIf(self.UserConfig().Git.IgnoreWhitespaceInDiffView, "--ignore-all-space").

pkg/commands/git_commands/stash_test.go

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ func TestStashStashEntryCmdObj(t *testing.T) {
103103
contextSize uint64
104104
similarityThreshold int
105105
ignoreWhitespace bool
106+
extDiffCmd string
106107
expected []string
107108
}
108109

@@ -113,31 +114,40 @@ func TestStashStashEntryCmdObj(t *testing.T) {
113114
contextSize: 3,
114115
similarityThreshold: 50,
115116
ignoreWhitespace: false,
116-
expected: []string{"git", "-C", "/path/to/worktree", "stash", "show", "-p", "--stat", "-u", "--color=always", "--unified=3", "--find-renames=50%", "refs/stash@{5}"},
117+
expected: []string{"git", "-C", "/path/to/worktree", "stash", "show", "-p", "--stat", "-u", "--no-ext-diff", "--color=always", "--unified=3", "--find-renames=50%", "refs/stash@{5}"},
117118
},
118119
{
119120
testName: "Show diff with custom context size",
120121
index: 5,
121122
contextSize: 77,
122123
similarityThreshold: 50,
123124
ignoreWhitespace: false,
124-
expected: []string{"git", "-C", "/path/to/worktree", "stash", "show", "-p", "--stat", "-u", "--color=always", "--unified=77", "--find-renames=50%", "refs/stash@{5}"},
125+
expected: []string{"git", "-C", "/path/to/worktree", "stash", "show", "-p", "--stat", "-u", "--no-ext-diff", "--color=always", "--unified=77", "--find-renames=50%", "refs/stash@{5}"},
125126
},
126127
{
127128
testName: "Show diff with custom similarity threshold",
128129
index: 5,
129130
contextSize: 3,
130131
similarityThreshold: 33,
131132
ignoreWhitespace: false,
132-
expected: []string{"git", "-C", "/path/to/worktree", "stash", "show", "-p", "--stat", "-u", "--color=always", "--unified=3", "--find-renames=33%", "refs/stash@{5}"},
133+
expected: []string{"git", "-C", "/path/to/worktree", "stash", "show", "-p", "--stat", "-u", "--no-ext-diff", "--color=always", "--unified=3", "--find-renames=33%", "refs/stash@{5}"},
134+
},
135+
{
136+
testName: "Show diff with external diff command",
137+
index: 5,
138+
contextSize: 3,
139+
similarityThreshold: 50,
140+
ignoreWhitespace: false,
141+
extDiffCmd: "difft --color=always",
142+
expected: []string{"git", "-C", "/path/to/worktree", "-c", "diff.external=difft --color=always", "stash", "show", "-p", "--stat", "-u", "--ext-diff", "--color=always", "--unified=3", "--find-renames=50%", "refs/stash@{5}"},
133143
},
134144
{
135145
testName: "Default case",
136146
index: 5,
137147
contextSize: 3,
138148
similarityThreshold: 50,
139149
ignoreWhitespace: true,
140-
expected: []string{"git", "-C", "/path/to/worktree", "stash", "show", "-p", "--stat", "-u", "--color=always", "--unified=3", "--ignore-all-space", "--find-renames=50%", "refs/stash@{5}"},
150+
expected: []string{"git", "-C", "/path/to/worktree", "stash", "show", "-p", "--stat", "-u", "--no-ext-diff", "--color=always", "--unified=3", "--ignore-all-space", "--find-renames=50%", "refs/stash@{5}"},
141151
},
142152
}
143153

@@ -147,6 +157,7 @@ func TestStashStashEntryCmdObj(t *testing.T) {
147157
userConfig.Git.IgnoreWhitespaceInDiffView = s.ignoreWhitespace
148158
userConfig.Git.DiffContextSize = s.contextSize
149159
userConfig.Git.RenameSimilarityThreshold = s.similarityThreshold
160+
userConfig.Git.Paging.ExternalDiffCommand = s.extDiffCmd
150161
repoPaths := RepoPaths{
151162
worktreePath: "/path/to/worktree",
152163
}

0 commit comments

Comments
 (0)