Skip to content

Commit e7c33a7

Browse files
committed
Always append -- to git show command
It is good practice to use a -- argument even if no further arguments follow. Doesn't really make a difference for this particular command though, I think.
1 parent 33a4fdf commit e7c33a7

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

pkg/commands/git_commands/commit.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,8 @@ func (self *CommitCommands) ShowCmdObj(hash string, filterPath string) *oscomman
270270
Arg(hash).
271271
ArgIf(self.UserConfig().Git.IgnoreWhitespaceInDiffView, "--ignore-all-space").
272272
Arg(fmt.Sprintf("--find-renames=%d%%", self.UserConfig().Git.RenameSimilarityThreshold)).
273-
ArgIf(filterPath != "", "--", filterPath).
273+
Arg("--").
274+
ArgIf(filterPath != "", filterPath).
274275
Dir(self.repoPaths.worktreePath).
275276
ToArgv()
276277

pkg/commands/git_commands/commit_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ func TestCommitShowCmdObj(t *testing.T) {
267267
similarityThreshold: 50,
268268
ignoreWhitespace: false,
269269
extDiffCmd: "",
270-
expected: []string{"-C", "/path/to/worktree", "-c", "diff.noprefix=false", "show", "--no-ext-diff", "--submodule", "--color=always", "--unified=3", "--stat", "--decorate", "-p", "1234567890", "--find-renames=50%"},
270+
expected: []string{"-C", "/path/to/worktree", "-c", "diff.noprefix=false", "show", "--no-ext-diff", "--submodule", "--color=always", "--unified=3", "--stat", "--decorate", "-p", "1234567890", "--find-renames=50%", "--"},
271271
},
272272
{
273273
testName: "Default case with filter path",
@@ -285,7 +285,7 @@ func TestCommitShowCmdObj(t *testing.T) {
285285
similarityThreshold: 50,
286286
ignoreWhitespace: false,
287287
extDiffCmd: "",
288-
expected: []string{"-C", "/path/to/worktree", "-c", "diff.noprefix=false", "show", "--no-ext-diff", "--submodule", "--color=always", "--unified=77", "--stat", "--decorate", "-p", "1234567890", "--find-renames=50%"},
288+
expected: []string{"-C", "/path/to/worktree", "-c", "diff.noprefix=false", "show", "--no-ext-diff", "--submodule", "--color=always", "--unified=77", "--stat", "--decorate", "-p", "1234567890", "--find-renames=50%", "--"},
289289
},
290290
{
291291
testName: "Show diff with custom similarity threshold",
@@ -294,7 +294,7 @@ func TestCommitShowCmdObj(t *testing.T) {
294294
similarityThreshold: 33,
295295
ignoreWhitespace: false,
296296
extDiffCmd: "",
297-
expected: []string{"-C", "/path/to/worktree", "-c", "diff.noprefix=false", "show", "--no-ext-diff", "--submodule", "--color=always", "--unified=3", "--stat", "--decorate", "-p", "1234567890", "--find-renames=33%"},
297+
expected: []string{"-C", "/path/to/worktree", "-c", "diff.noprefix=false", "show", "--no-ext-diff", "--submodule", "--color=always", "--unified=3", "--stat", "--decorate", "-p", "1234567890", "--find-renames=33%", "--"},
298298
},
299299
{
300300
testName: "Show diff, ignoring whitespace",
@@ -303,7 +303,7 @@ func TestCommitShowCmdObj(t *testing.T) {
303303
similarityThreshold: 50,
304304
ignoreWhitespace: true,
305305
extDiffCmd: "",
306-
expected: []string{"-C", "/path/to/worktree", "-c", "diff.noprefix=false", "show", "--no-ext-diff", "--submodule", "--color=always", "--unified=77", "--stat", "--decorate", "-p", "1234567890", "--ignore-all-space", "--find-renames=50%"},
306+
expected: []string{"-C", "/path/to/worktree", "-c", "diff.noprefix=false", "show", "--no-ext-diff", "--submodule", "--color=always", "--unified=77", "--stat", "--decorate", "-p", "1234567890", "--ignore-all-space", "--find-renames=50%", "--"},
307307
},
308308
{
309309
testName: "Show diff with external diff command",
@@ -312,7 +312,7 @@ func TestCommitShowCmdObj(t *testing.T) {
312312
similarityThreshold: 50,
313313
ignoreWhitespace: false,
314314
extDiffCmd: "difft --color=always",
315-
expected: []string{"-C", "/path/to/worktree", "-c", "diff.external=difft --color=always", "-c", "diff.noprefix=false", "show", "--ext-diff", "--submodule", "--color=always", "--unified=3", "--stat", "--decorate", "-p", "1234567890", "--find-renames=50%"},
315+
expected: []string{"-C", "/path/to/worktree", "-c", "diff.external=difft --color=always", "-c", "diff.noprefix=false", "show", "--ext-diff", "--submodule", "--color=always", "--unified=3", "--stat", "--decorate", "-p", "1234567890", "--find-renames=50%", "--"},
316316
},
317317
}
318318

0 commit comments

Comments
 (0)