mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-01-20 05:19:24 +02:00
Resolve the prompt just before using it
In case a later command depends on a prompt input from a previous one we need to evaluate it only after the previous prompt has been confirmed.
This commit is contained in:
parent
a6ebc5869e
commit
b3d086bdc1
@ -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:
|
||||
|
@ -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")
|
||||
},
|
||||
})
|
@ -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,
|
||||
|
@ -0,0 +1 @@
|
||||
baz
|
@ -0,0 +1 @@
|
||||
ref: refs/heads/master
|
@ -0,0 +1,12 @@
|
||||
[core]
|
||||
repositoryformatversion = 0
|
||||
filemode = true
|
||||
bare = false
|
||||
logallrefupdates = true
|
||||
[user]
|
||||
email = CI@example.com
|
||||
name = CI
|
||||
[commit]
|
||||
gpgSign = false
|
||||
[protocol "file"]
|
||||
allow = always
|
@ -0,0 +1 @@
|
||||
Unnamed repository; edit this file 'description' to name the repository.
|
Binary file not shown.
@ -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]
|
||||
# *~
|
@ -0,0 +1,6 @@
|
||||
0000000000000000000000000000000000000000 44531ed59352b290ebe5d6bebeada267dff76fd5 CI <CI@example.com> 1669412559 +0100 commit (initial): foo
|
||||
44531ed59352b290ebe5d6bebeada267dff76fd5 44531ed59352b290ebe5d6bebeada267dff76fd5 CI <CI@example.com> 1669412559 +0100 checkout: moving from master to feature/foo
|
||||
44531ed59352b290ebe5d6bebeada267dff76fd5 b3518a56dbbd6df36eff0613aea30ab8e6659b26 CI <CI@example.com> 1669412559 +0100 commit: bar
|
||||
b3518a56dbbd6df36eff0613aea30ab8e6659b26 b3518a56dbbd6df36eff0613aea30ab8e6659b26 CI <CI@example.com> 1669412559 +0100 checkout: moving from feature/foo to feature/bar
|
||||
b3518a56dbbd6df36eff0613aea30ab8e6659b26 083b75d86104b3a7d89d9c355719b2aa9113cab9 CI <CI@example.com> 1669412559 +0100 commit: baz
|
||||
083b75d86104b3a7d89d9c355719b2aa9113cab9 44531ed59352b290ebe5d6bebeada267dff76fd5 CI <CI@example.com> 1669412567 +0100 checkout: moving from feature/bar to master
|
@ -0,0 +1,2 @@
|
||||
0000000000000000000000000000000000000000 b3518a56dbbd6df36eff0613aea30ab8e6659b26 CI <CI@example.com> 1669412559 +0100 branch: Created from HEAD
|
||||
b3518a56dbbd6df36eff0613aea30ab8e6659b26 083b75d86104b3a7d89d9c355719b2aa9113cab9 CI <CI@example.com> 1669412559 +0100 commit: baz
|
@ -0,0 +1,2 @@
|
||||
0000000000000000000000000000000000000000 44531ed59352b290ebe5d6bebeada267dff76fd5 CI <CI@example.com> 1669412559 +0100 branch: Created from HEAD
|
||||
44531ed59352b290ebe5d6bebeada267dff76fd5 b3518a56dbbd6df36eff0613aea30ab8e6659b26 CI <CI@example.com> 1669412559 +0100 commit: bar
|
@ -0,0 +1 @@
|
||||
0000000000000000000000000000000000000000 44531ed59352b290ebe5d6bebeada267dff76fd5 CI <CI@example.com> 1669412559 +0100 commit (initial): foo
|
@ -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™
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1 @@
|
||||
083b75d86104b3a7d89d9c355719b2aa9113cab9
|
@ -0,0 +1 @@
|
||||
b3518a56dbbd6df36eff0613aea30ab8e6659b26
|
@ -0,0 +1 @@
|
||||
44531ed59352b290ebe5d6bebeada267dff76fd5
|
Loading…
x
Reference in New Issue
Block a user