Skip to content

Commit ea50139

Browse files
committed
Set SelectedPath to SelectedCommitFilePath in CommitFiles context
1 parent fd41ee5 commit ea50139

File tree

3 files changed

+54
-2
lines changed

3 files changed

+54
-2
lines changed

pkg/gui/services/custom_commands/session_state_loader.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,9 +193,16 @@ func (self *SessionStateLoader) call() *SessionState {
193193
selectedCommit = selectedSubCommit
194194
}
195195

196+
selectedPath := self.c.Contexts().Files.GetSelectedPath()
197+
selectedCommitFilePath := self.c.Contexts().CommitFiles.GetSelectedPath()
198+
199+
if self.c.Context().IsCurrent(self.c.Contexts().CommitFiles) {
200+
selectedPath = selectedCommitFilePath
201+
}
202+
196203
return &SessionState{
197204
SelectedFile: fileShimFromModelFile(self.c.Contexts().Files.GetSelectedFile()),
198-
SelectedPath: self.c.Contexts().Files.GetSelectedPath(),
205+
SelectedPath: selectedPath,
199206
SelectedLocalCommit: selectedLocalCommit,
200207
SelectedReflogCommit: selectedReflogCommit,
201208
SelectedSubCommit: selectedSubCommit,
@@ -206,7 +213,7 @@ func (self *SessionStateLoader) call() *SessionState {
206213
SelectedTag: tagShimFromModelRemote(self.c.Contexts().Tags.GetSelected()),
207214
SelectedStashEntry: stashEntryShimFromModelRemote(self.c.Contexts().Stash.GetSelected()),
208215
SelectedCommitFile: commitFileShimFromModelRemote(self.c.Contexts().CommitFiles.GetSelectedFile()),
209-
SelectedCommitFilePath: self.c.Contexts().CommitFiles.GetSelectedPath(),
216+
SelectedCommitFilePath: selectedCommitFilePath,
210217
SelectedWorktree: worktreeShimFromModelRemote(self.c.Contexts().Worktrees.GetSelected()),
211218
CheckedOutBranch: branchShimFromModelBranch(self.refsHelper.GetCheckedOutRef()),
212219
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package custom_commands
2+
3+
import (
4+
"github.com/jesseduffield/lazygit/pkg/config"
5+
. "github.com/jesseduffield/lazygit/pkg/integration/components"
6+
)
7+
8+
var SelectedPath = NewIntegrationTest(NewIntegrationTestArgs{
9+
Description: "Use the {{ .SelectedPath }} template variable in different contexts",
10+
ExtraCmdArgs: []string{},
11+
Skip: false,
12+
SetupRepo: func(shell *Shell) {
13+
shell.CreateDir("folder1")
14+
shell.CreateFileAndAdd("folder1/file1", "")
15+
shell.Commit("commit")
16+
shell.CreateDir("folder2")
17+
shell.CreateFile("folder2/file2", "")
18+
},
19+
SetupConfig: func(cfg *config.AppConfig) {
20+
cfg.UserConfig.CustomCommands = []config.CustomCommand{
21+
{
22+
Key: "X",
23+
Context: "global",
24+
Command: "printf '%s' '{{ .SelectedPath }}' > file.txt",
25+
},
26+
}
27+
},
28+
Run: func(t *TestDriver, keys config.KeybindingConfig) {
29+
t.Views().Files().
30+
Focus().
31+
NavigateToLine(Contains("file2"))
32+
t.GlobalPress("X")
33+
t.FileSystem().FileContent("file.txt", Equals("folder2/file2"))
34+
35+
t.Views().Commits().
36+
Focus().
37+
PressEnter()
38+
t.Views().CommitFiles().
39+
IsFocused().
40+
NavigateToLine(Contains("file1"))
41+
t.GlobalPress("X")
42+
t.FileSystem().FileContent("file.txt", Equals("folder1/file1"))
43+
},
44+
})

pkg/integration/tests/test_list.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ var tests = []*components.IntegrationTest{
130130
custom_commands.MultiplePrompts,
131131
custom_commands.OmitFromHistory,
132132
custom_commands.SelectedCommit,
133+
custom_commands.SelectedPath,
133134
custom_commands.ShowOutputInPanel,
134135
custom_commands.SuggestionsCommand,
135136
custom_commands.SuggestionsPreset,

0 commit comments

Comments
 (0)