Repository: jesseduffield/lazygit (language: go)

Issue:
{{index .PromptResponses 0 }} on second prompt doesn't work
**Describe the bug**
A clear and concise description of what the bug is.

I added this custom command
```yml
- key : '<c-n>'
    description: 'Checkout a remote branch as FETCH_HEAD'
    command: "git fetch {{ index .PromptResponses 0 }} {{ index .PromptResponses 1 }} && git switch {{ index .PromptResponses 1 }}"
    context: 'localBranches'
    prompts:
      - type: 'input'
        title: 'Remote:'
        initialValue: "{{index .SelectedRemote.Name }}"
      - type: 'menuFromCommand'
        title: 'Remote branch:'
        command: "git branch  -r --list {{index .PromptResponses 0 }}/*"
        filter: "{{index .PromptResponses 0 }}/(?P<branch>.*)"
        valueFormat: '{{ .branch }}'
        labelFormat: '{{ .branch | green }}'
```

but I have noting in `{{index .PromptResponses 0 }}` on the second prompt command I see only this

<img width="503" alt="Capture d’écran 2022-08-08 à 21 07 29" src="https://user-images.githubusercontent.com/404449/183494969-158fd747-3de2-416f-9ad8-5707a11df9c8.png">


**To Reproduce**
Steps to reproduce the behavior:

1. create a config file on macOS
2. add a custom command
3. open a fresh lazygit using iTerm2
4. I run `<c-n>`
5. i have a popup with `origin`
6. I use `enter` with my keyboard
7. I saw the picture in the log
8. I saw a popup with empty `branch` and just the cancel button    

**Expected behavior**
A clear and concise description of what you expected to happen.
need to have `origin` in the command logged
`git branch -r --list origin/*`

**Screenshots**
If applicable, add screenshots to help explain your problem.


<img width="460" alt="Capture d’écran 2022-08-08 à 21 11 47" src="https://user-images.githubusercontent.com/404449/183495669-4bf50e59-3dbf-4ae6-af8c-6d26ae29befa.png">



**Version info:**
_commit=, build date=, build source=homebrew, version=0.35, os=darwin, arch=amd64_
_git version 2.37.1_

**Additional context**
Add any other context about the problem here.

**Note:** please try updating to the latest version or [manually building](https://github.com/jesseduffield/lazygit/#manual) the latest `master` to see if the issue still occurs.

<!--
If you want to try and debug this issue yourself, you can run `lazygit --debug` in one terminal panel and `lazygit --logs` in another to view the logs.
-->



Discussion / hints:
Just a quick question to help me understand this, this command should just checkout a remote branch?
> Just a quick question to help me understand this, this command should just checkout a remote branch?

yes this command `"git fetch {{ index .PromptResponses 0 }} {{ index .PromptResponses 1 }} && git switch {{ index .PromptResponses 1 }}"` is for checkout the remote branch,

and the command `"git branch  -r --list {{index .PromptResponses 0 }}/*"` is for list all available branch on remote.

but I have this issue on other command I used every day, actually other command I hard coded the `origin` remote name, but sometimes I need to use `upstream` remote and I can't do that due the issue.

the issue is on `{{index .PromptResponses 0 }} ` which don't have any value of the first alert prompt to use it on the second alert prompt
Alright, that's an issue that will be looked at. Thanks for reporting!

As a potential workaround, have you tried going to the `Local Branches` pane, pressing `]` to reach the `Remotes` tab? After picking a remote you can checkout a branch by pressing `space`.
> Alright, that's an issue that will be looked at. Thanks for reporting!
> 
> As a potential workaround, have you tried going to the `Local Branches` pane, pressing `]` to reach the `Remotes` tab? After picking a remote you can checkout a branch by pressing `space`.

yes I know this feature, I used sometimes, but I prefer to have a prompt alert with all remote branchs, thanks @mark2185 
FWIW all the action for this lives in `pkg/gui/services/custom_commands/handler_creator.go` specifically HandlerCreator's call method. Should be fairly easy to get to the bottom of
In other news, isn't this exact feature supposed to be behind the mapping `c`, i.e. `checkout by name`?

It brings up a prompt to find any branch by name :thinking: 
Any news about the fix on this issue 
No progress has been made. But I bet this would be a quick fix so I'll chuck a good first issue label on it. Is this something you'd be up to investigating @amine2233 ? I can give pointers where needed

Fix patch:
diff --git a/pkg/gui/services/custom_commands/handler_creator.go b/pkg/gui/services/custom_commands/handler_creator.go
index bad972bd67e..4a81b08b589 100644
--- a/pkg/gui/services/custom_commands/handler_creator.go
+++ b/pkg/gui/services/custom_commands/handler_creator.go
@@ -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:


Test patch:
diff --git a/pkg/integration/tests/custom_commands/menu_from_commands_output.go b/pkg/integration/tests/custom_commands/menu_from_commands_output.go
new file mode 100644
index 00000000000..fdd207c4c47
--- /dev/null
+++ b/pkg/integration/tests/custom_commands/menu_from_commands_output.go
@@ -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")
+	},
+})
diff --git a/pkg/integration/tests/tests.go b/pkg/integration/tests/tests.go
index f097b032d22..6c074bb1043 100644
--- a/pkg/integration/tests/tests.go
+++ b/pkg/integration/tests/tests.go
@@ -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,
diff --git a/test/integration_new/custom_commands/menu_from_commands_output/expected/repo/.git_keep/COMMIT_EDITMSG b/test/integration_new/custom_commands/menu_from_commands_output/expected/repo/.git_keep/COMMIT_EDITMSG
new file mode 100644
index 00000000000..76018072e09
--- /dev/null
+++ b/test/integration_new/custom_commands/menu_from_commands_output/expected/repo/.git_keep/COMMIT_EDITMSG
@@ -0,0 +1,1 @@
+baz
diff --git a/test/integration_new/custom_commands/menu_from_commands_output/expected/repo/.git_keep/FETCH_HEAD b/test/integration_new/custom_commands/menu_from_commands_output/expected/repo/.git_keep/FETCH_HEAD
new file mode 100644
index 00000000000..e69de29bb2d
diff --git a/test/integration_new/custom_commands/menu_from_commands_output/expected/repo/.git_keep/HEAD b/test/integration_new/custom_commands/menu_from_commands_output/expected/repo/.git_keep/HEAD
new file mode 100644
index 00000000000..cb089cd89a7
--- /dev/null
+++ b/test/integration_new/custom_commands/menu_from_commands_output/expected/repo/.git_keep/HEAD
@@ -0,0 +1,1 @@
+ref: refs/heads/master
diff --git a/test/integration_new/custom_commands/menu_from_commands_output/expected/repo/.git_keep/config b/test/integration_new/custom_commands/menu_from_commands_output/expected/repo/.git_keep/config
new file mode 100644
index 00000000000..2b89b8630f9
--- /dev/null
+++ b/test/integration_new/custom_commands/menu_from_commands_output/expected/repo/.git_keep/config
@@ -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
diff --git a/test/integration_new/custom_commands/menu_from_commands_output/expected/repo/.git_keep/description b/test/integration_new/custom_commands/menu_from_commands_output/expected/repo/.git_keep/description
new file mode 100644
index 00000000000..498b267a8c7
--- /dev/null
+++ b/test/integration_new/custom_commands/menu_from_commands_output/expected/repo/.git_keep/description
@@ -0,0 +1,1 @@
+Unnamed repository; edit this file 'description' to name the repository.
diff --git a/test/integration_new/custom_commands/menu_from_commands_output/expected/repo/.git_keep/index b/test/integration_new/custom_commands/menu_from_commands_output/expected/repo/.git_keep/index
new file mode 100644
index 00000000000..65d675154f2
Binary files /dev/null and b/test/integration_new/custom_commands/menu_from_commands_output/expected/repo/.git_keep/index differ
diff --git a/test/integration_new/custom_commands/menu_from_commands_output/expected/repo/.git_keep/info/exclude b/test/integration_new/custom_commands/menu_from_commands_output/expected/repo/.git_keep/info/exclude
new file mode 100644
index 00000000000..a5196d1be8f
--- /dev/null
+++ b/test/integration_new/custom_commands/menu_from_commands_output/expected/repo/.git_keep/info/exclude
@@ -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]
+# *~
diff --git a/test/integration_new/custom_commands/menu_from_commands_output/expected/repo/.git_keep/logs/HEAD b/test/integration_new/custom_commands/menu_from_commands_output/expected/repo/.git_keep/logs/HEAD
new file mode 100644
index 00000000000..3905c1bade4
--- /dev/null
+++ b/test/integration_new/custom_commands/menu_from_commands_output/expected/repo/.git_keep/logs/HEAD
@@ -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
diff --git a/test/integration_new/custom_commands/menu_from_commands_output/expected/repo/.git_keep/logs/refs/heads/feature/bar b/test/integration_new/custom_commands/menu_from_commands_output/expected/repo/.git_keep/logs/refs/heads/feature/bar
new file mode 100644
index 00000000000..77d5c6099c8
--- /dev/null
+++ b/test/integration_new/custom_commands/menu_from_commands_output/expected/repo/.git_keep/logs/refs/heads/feature/bar
@@ -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
diff --git a/test/integration_new/custom_commands/menu_from_commands_output/expected/repo/.git_keep/logs/refs/heads/feature/foo b/test/integration_new/custom_commands/menu_from_commands_output/expected/repo/.git_keep/logs/refs/heads/feature/foo
new file mode 100644
index 00000000000..a09bd9f99a5
--- /dev/null
+++ b/test/integration_new/custom_commands/menu_from_commands_output/expected/repo/.git_keep/logs/refs/heads/feature/foo
@@ -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
diff --git a/test/integration_new/custom_commands/menu_from_commands_output/expected/repo/.git_keep/logs/refs/heads/master b/test/integration_new/custom_commands/menu_from_commands_output/expected/repo/.git_keep/logs/refs/heads/master
new file mode 100644
index 00000000000..d1b8c187e98
--- /dev/null
+++ b/test/integration_new/custom_commands/menu_from_commands_output/expected/repo/.git_keep/logs/refs/heads/master
@@ -0,0 +1,1 @@
+0000000000000000000000000000000000000000 44531ed59352b290ebe5d6bebeada267dff76fd5 CI <CI@example.com> 1669412559 +0100	commit (initial): foo
diff --git a/test/integration_new/custom_commands/menu_from_commands_output/expected/repo/.git_keep/objects/08/3b75d86104b3a7d89d9c355719b2aa9113cab9 b/test/integration_new/custom_commands/menu_from_commands_output/expected/repo/.git_keep/objects/08/3b75d86104b3a7d89d9c355719b2aa9113cab9
new file mode 100644
index 00000000000..e428309a2f6
--- /dev/null
+++ b/test/integration_new/custom_commands/menu_from_commands_output/expected/repo/.git_keep/objects/08/3b75d86104b3a7d89d9c355719b2aa9113cab9
@@ -0,0 +1,3 @@
+x��M
+�0@a�9E��L��H��1f�	
+ƖA<�=��Ƿxe��1�#8�]�F�>Ղ�Ab@����sn�	��x�װ�˜��T�-���+`Ɋ�H<~����y��y�����KY�d"E�S"{`�zL����Y�9�
\ No newline at end of file
diff --git a/test/integration_new/custom_commands/menu_from_commands_output/expected/repo/.git_keep/objects/44/531ed59352b290ebe5d6bebeada267dff76fd5 b/test/integration_new/custom_commands/menu_from_commands_output/expected/repo/.git_keep/objects/44/531ed59352b290ebe5d6bebeada267dff76fd5
new file mode 100644
index 00000000000..07469bc40aa
Binary files /dev/null and b/test/integration_new/custom_commands/menu_from_commands_output/expected/repo/.git_keep/objects/44/531ed59352b290ebe5d6bebeada267dff76fd5 differ
diff --git a/test/integration_new/custom_commands/menu_from_commands_output/expected/repo/.git_keep/objects/4b/825dc642cb6eb9a060e54bf8d69288fbee4904 b/test/integration_new/custom_commands/menu_from_commands_output/expected/repo/.git_keep/objects/4b/825dc642cb6eb9a060e54bf8d69288fbee4904
new file mode 100644
index 00000000000..adf64119a33
Binary files /dev/null and b/test/integration_new/custom_commands/menu_from_commands_output/expected/repo/.git_keep/objects/4b/825dc642cb6eb9a060e54bf8d69288fbee4904 differ
diff --git a/test/integration_new/custom_commands/menu_from_commands_output/expected/repo/.git_keep/objects/b3/518a56dbbd6df36eff0613aea30ab8e6659b26 b/test/integration_new/custom_commands/menu_from_commands_output/expected/repo/.git_keep/objects/b3/518a56dbbd6df36eff0613aea30ab8e6659b26
new file mode 100644
index 00000000000..5dca5a75da1
Binary files /dev/null and b/test/integration_new/custom_commands/menu_from_commands_output/expected/repo/.git_keep/objects/b3/518a56dbbd6df36eff0613aea30ab8e6659b26 differ
diff --git a/test/integration_new/custom_commands/menu_from_commands_output/expected/repo/.git_keep/refs/heads/feature/bar b/test/integration_new/custom_commands/menu_from_commands_output/expected/repo/.git_keep/refs/heads/feature/bar
new file mode 100644
index 00000000000..9dfead7947b
--- /dev/null
+++ b/test/integration_new/custom_commands/menu_from_commands_output/expected/repo/.git_keep/refs/heads/feature/bar
@@ -0,0 +1,1 @@
+083b75d86104b3a7d89d9c355719b2aa9113cab9
diff --git a/test/integration_new/custom_commands/menu_from_commands_output/expected/repo/.git_keep/refs/heads/feature/foo b/test/integration_new/custom_commands/menu_from_commands_output/expected/repo/.git_keep/refs/heads/feature/foo
new file mode 100644
index 00000000000..0fd10f1716a
--- /dev/null
+++ b/test/integration_new/custom_commands/menu_from_commands_output/expected/repo/.git_keep/refs/heads/feature/foo
@@ -0,0 +1,1 @@
+b3518a56dbbd6df36eff0613aea30ab8e6659b26
diff --git a/test/integration_new/custom_commands/menu_from_commands_output/expected/repo/.git_keep/refs/heads/master b/test/integration_new/custom_commands/menu_from_commands_output/expected/repo/.git_keep/refs/heads/master
new file mode 100644
index 00000000000..20320259942
--- /dev/null
+++ b/test/integration_new/custom_commands/menu_from_commands_output/expected/repo/.git_keep/refs/heads/master
@@ -0,0 +1,1 @@
+44531ed59352b290ebe5d6bebeada267dff76fd5