Skip to content

Commit af9699e

Browse files
Add --include-untracked flag to stash show command (#3932)
- **PR Description** This PR fixes #3931 by adding `--include-untracked` to `git stash show` command. Untracked stashed file diff is now shown in the main view. ![before this PR](https://github.com/user-attachments/assets/81097c71-3764-4467-a960-a87c51921139) *Before: the untracked stashed file is not shown in lazygit*. ![after this PR](https://github.com/user-attachments/assets/4aafd5f6-5305-4f9b-9068-1570d22e755c) *After: the untracked stashed file diff is shown in lazygit*. ## One Issue This PR does not fix the fact that untracked stashed files are not shown in the list of files in the "Stash" panel when entering a stash entry, I could not find an easy way to make them appear there. * [x] Cheatsheets are up-to-date (run `go generate ./...`) * [x] Code has been formatted (see [here](https://github.com/jesseduffield/lazygit/blob/master/CONTRIBUTING.md#code-formatting)) * [x] Tests have been added/updated (see [here](https://github.com/jesseduffield/lazygit/blob/master/pkg/integration/README.md) for the integration test guide) * [x] Text is internationalised (see [here](https://github.com/jesseduffield/lazygit/blob/master/CONTRIBUTING.md#internationalisation)) * [ ] If a new UserConfig entry was added, make sure it can be hot-reloaded (see [here](https://github.com/jesseduffield/lazygit/blob/master/docs/dev/Codebase_Guide.md#using-userconfig)) * [ ] Docs have been updated if necessary * [x] You've read through your own file changes for silly mistakes etc
2 parents 16f5348 + d92c6d1 commit af9699e

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

Diff for: pkg/commands/git_commands/stash.go

+2
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,11 @@ func (self *StashCommands) Hash(index int) (string, error) {
8181
}
8282

8383
func (self *StashCommands) ShowStashEntryCmdObj(index int) oscommands.ICmdObj {
84+
// "-u" is the same as "--include-untracked", but the latter fails in older git versions for some reason
8485
cmdArgs := NewGitCmd("stash").Arg("show").
8586
Arg("-p").
8687
Arg("--stat").
88+
Arg("-u").
8789
Arg(fmt.Sprintf("--color=%s", self.UserConfig().Git.Paging.ColorArg)).
8890
Arg(fmt.Sprintf("--unified=%d", self.AppState.DiffContextSize)).
8991
ArgIf(self.AppState.IgnoreWhitespaceInDiffView, "--ignore-all-space").

Diff for: pkg/commands/git_commands/stash_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -113,31 +113,31 @@ func TestStashStashEntryCmdObj(t *testing.T) {
113113
contextSize: 3,
114114
similarityThreshold: 50,
115115
ignoreWhitespace: false,
116-
expected: []string{"git", "-C", "/path/to/worktree", "stash", "show", "-p", "--stat", "--color=always", "--unified=3", "--find-renames=50%", "stash@{5}"},
116+
expected: []string{"git", "-C", "/path/to/worktree", "stash", "show", "-p", "--stat", "-u", "--color=always", "--unified=3", "--find-renames=50%", "stash@{5}"},
117117
},
118118
{
119119
testName: "Show diff with custom context size",
120120
index: 5,
121121
contextSize: 77,
122122
similarityThreshold: 50,
123123
ignoreWhitespace: false,
124-
expected: []string{"git", "-C", "/path/to/worktree", "stash", "show", "-p", "--stat", "--color=always", "--unified=77", "--find-renames=50%", "stash@{5}"},
124+
expected: []string{"git", "-C", "/path/to/worktree", "stash", "show", "-p", "--stat", "-u", "--color=always", "--unified=77", "--find-renames=50%", "stash@{5}"},
125125
},
126126
{
127127
testName: "Show diff with custom similarity threshold",
128128
index: 5,
129129
contextSize: 3,
130130
similarityThreshold: 33,
131131
ignoreWhitespace: false,
132-
expected: []string{"git", "-C", "/path/to/worktree", "stash", "show", "-p", "--stat", "--color=always", "--unified=3", "--find-renames=33%", "stash@{5}"},
132+
expected: []string{"git", "-C", "/path/to/worktree", "stash", "show", "-p", "--stat", "-u", "--color=always", "--unified=3", "--find-renames=33%", "stash@{5}"},
133133
},
134134
{
135135
testName: "Default case",
136136
index: 5,
137137
contextSize: 3,
138138
similarityThreshold: 50,
139139
ignoreWhitespace: true,
140-
expected: []string{"git", "-C", "/path/to/worktree", "stash", "show", "-p", "--stat", "--color=always", "--unified=3", "--ignore-all-space", "--find-renames=50%", "stash@{5}"},
140+
expected: []string{"git", "-C", "/path/to/worktree", "stash", "show", "-p", "--stat", "-u", "--color=always", "--unified=3", "--ignore-all-space", "--find-renames=50%", "stash@{5}"},
141141
},
142142
}
143143

0 commit comments

Comments
 (0)