Skip to content

Commit

Permalink
Merge pull request jesseduffield#2296 from jesseduffield/fix-prompt-r…
Browse files Browse the repository at this point in the history
…esponse-not-stored
  • Loading branch information
jesseduffield authored Nov 26, 2022
2 parents a6ebc58 + b3d086b commit 773eb03
Show file tree
Hide file tree
Showing 21 changed files with 124 additions and 4 deletions.
20 changes: 16 additions & 4 deletions pkg/gui/services/custom_commands/handler_creator.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,26 +67,38 @@ func (self *HandlerCreator) call(customCommand config.CustomCommand) func() erro
}

resolveTemplate := self.getResolveTemplateFn(form, promptResponses, sessionState)
resolvedPrompt, err := self.resolver.resolvePrompt(&prompt, resolveTemplate)
if err != nil {
return self.c.Error(err)
}

switch prompt.Type {
case "input":
f = func() error {
resolvedPrompt, err := self.resolver.resolvePrompt(&prompt, resolveTemplate)
if err != nil {
return self.c.Error(err)
}
return self.inputPrompt(resolvedPrompt, wrappedF)
}
case "menu":
f = func() error {
resolvedPrompt, err := self.resolver.resolvePrompt(&prompt, resolveTemplate)
if err != nil {
return self.c.Error(err)
}
return self.menuPrompt(resolvedPrompt, wrappedF)
}
case "menuFromCommand":
f = func() error {
resolvedPrompt, err := self.resolver.resolvePrompt(&prompt, resolveTemplate)
if err != nil {
return self.c.Error(err)
}
return self.menuPromptFromCommand(resolvedPrompt, wrappedF)
}
case "confirm":
f = func() error {
resolvedPrompt, err := self.resolver.resolvePrompt(&prompt, resolveTemplate)
if err != nil {
return self.c.Error(err)
}
return self.confirmPrompt(resolvedPrompt, g)
}
default:
Expand Down
69 changes: 69 additions & 0 deletions pkg/integration/tests/custom_commands/menu_from_commands_output.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package custom_commands

import (
"github.com/jesseduffield/lazygit/pkg/config"
. "github.com/jesseduffield/lazygit/pkg/integration/components"
)

var MenuFromCommandsOutput = NewIntegrationTest(NewIntegrationTestArgs{
Description: "Using prompt response in menuFromCommand entries",
ExtraCmdArgs: "",
Skip: false,
SetupRepo: func(shell *Shell) {
shell.
EmptyCommit("foo").
NewBranch("feature/foo").
EmptyCommit("bar").
NewBranch("feature/bar").
EmptyCommit("baz")
},
SetupConfig: func(cfg *config.AppConfig) {
cfg.UserConfig.CustomCommands = []config.CustomCommand{
{
Key: "a",
Context: "localBranches",
Command: "git checkout {{ index .PromptResponses 1 }}",
Prompts: []config.CustomCommandPrompt{
{
Type: "input",
Title: "Which git command do you want to run?",
InitialValue: "branch",
},
{
Type: "menuFromCommand",
Title: "Branch:",
Command: `git {{ index .PromptResponses 0 }} --format='%(refname:short)'`,
Filter: "(?P<branch>.*)",
ValueFormat: `{{ .branch }}`,
LabelFormat: `{{ .branch | green }}`,
},
},
},
}
},
Run: func(
shell *Shell,
input *Input,
assert *Assert,
keys config.KeybindingConfig,
) {
assert.WorkingTreeFileCount(0)
input.SwitchToBranchesWindow()

input.PressKeys("a")

assert.InPrompt()
assert.MatchCurrentViewTitle(Equals("Which git command do you want to run?"))
assert.MatchSelectedLine(Equals("branch"))
input.Confirm()

assert.InMenu()
assert.MatchCurrentViewTitle(Equals("Branch:"))
input.NextItem()
input.NextItem()
assert.MatchSelectedLine(Equals("master"))
input.Confirm()

assert.CurrentBranchName("master")
},
})
1 change: 1 addition & 0 deletions pkg/integration/tests/tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ var tests = []*components.IntegrationTest{
custom_commands.Basic,
custom_commands.FormPrompts,
custom_commands.MenuFromCommand,
custom_commands.MenuFromCommandsOutput,
custom_commands.MultiplePrompts,
file.DirWithUntrackedFile,
interactive_rebase.AmendMerge,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
baz
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ref: refs/heads/master
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
[user]
email = [email protected]
name = CI
[commit]
gpgSign = false
[protocol "file"]
allow = always
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Unnamed repository; edit this file 'description' to name the repository.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# git ls-files --others --exclude-from=.git/info/exclude
# Lines that start with '#' are comments.
# For a project mostly in C, the following would be a good set of
# exclude patterns (uncomment them if you want to use them):
# *.[oa]
# *~
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
0000000000000000000000000000000000000000 44531ed59352b290ebe5d6bebeada267dff76fd5 CI <[email protected]> 1669412559 +0100 commit (initial): foo
44531ed59352b290ebe5d6bebeada267dff76fd5 44531ed59352b290ebe5d6bebeada267dff76fd5 CI <[email protected]> 1669412559 +0100 checkout: moving from master to feature/foo
44531ed59352b290ebe5d6bebeada267dff76fd5 b3518a56dbbd6df36eff0613aea30ab8e6659b26 CI <[email protected]> 1669412559 +0100 commit: bar
b3518a56dbbd6df36eff0613aea30ab8e6659b26 b3518a56dbbd6df36eff0613aea30ab8e6659b26 CI <[email protected]> 1669412559 +0100 checkout: moving from feature/foo to feature/bar
b3518a56dbbd6df36eff0613aea30ab8e6659b26 083b75d86104b3a7d89d9c355719b2aa9113cab9 CI <[email protected]> 1669412559 +0100 commit: baz
083b75d86104b3a7d89d9c355719b2aa9113cab9 44531ed59352b290ebe5d6bebeada267dff76fd5 CI <[email protected]> 1669412567 +0100 checkout: moving from feature/bar to master
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
0000000000000000000000000000000000000000 b3518a56dbbd6df36eff0613aea30ab8e6659b26 CI <[email protected]> 1669412559 +0100 branch: Created from HEAD
b3518a56dbbd6df36eff0613aea30ab8e6659b26 083b75d86104b3a7d89d9c355719b2aa9113cab9 CI <[email protected]> 1669412559 +0100 commit: baz
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
0000000000000000000000000000000000000000 44531ed59352b290ebe5d6bebeada267dff76fd5 CI <[email protected]> 1669412559 +0100 branch: Created from HEAD
44531ed59352b290ebe5d6bebeada267dff76fd5 b3518a56dbbd6df36eff0613aea30ab8e6659b26 CI <[email protected]> 1669412559 +0100 commit: bar
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0000000000000000000000000000000000000000 44531ed59352b290ebe5d6bebeada267dff76fd5 CI <[email protected]> 1669412559 +0100 commit (initial): foo
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
x��M
�0@a�9E��L�� H��1f�
ƖA<�=��Ƿxe��1�#8�]�F�>Ղ�Ab@����sn� ��x�װ�˜��T�-���+`Ɋ�H<~����y��y�����KY�d"E�S"{`�zL����Y�9�
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
083b75d86104b3a7d89d9c355719b2aa9113cab9
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
b3518a56dbbd6df36eff0613aea30ab8e6659b26
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
44531ed59352b290ebe5d6bebeada267dff76fd5

0 comments on commit 773eb03

Please sign in to comment.