lazygit icon indicating copy to clipboard operation
lazygit copied to clipboard

{{index .PromptResponses 0 }} on second prompt doesn't work

Open amine2233 opened this issue 3 years ago • 6 comments

Describe the bug A clear and concise description of what the bug is.

I added this custom command

- 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

Capture d’écran 2022-08-08 à 21 07 29

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.

Capture d’écran 2022-08-08 à 21 11 47

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 the latest master to see if the issue still occurs.

amine2233 avatar Aug 08 '22 19:08 amine2233

Just a quick question to help me understand this, this command should just checkout a remote branch?

mark2185 avatar Aug 08 '22 19:08 mark2185

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

amine2233 avatar Aug 09 '22 06:08 amine2233

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.

mark2185 avatar Aug 09 '22 06:08 mark2185

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

amine2233 avatar Aug 09 '22 08:08 amine2233

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

jesseduffield avatar Aug 09 '22 12:08 jesseduffield

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:

mark2185 avatar Aug 09 '22 12:08 mark2185

Any news about the fix on this issue

amine2233 avatar Nov 24 '22 19:11 amine2233

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

jesseduffield avatar Nov 24 '22 22:11 jesseduffield

@amine2233 could you check to see if the current master works?

mark2185 avatar Nov 26 '22 07:11 mark2185

@jesseduffield & @mark2185, sorry for my late answer, it's work perfectly, I'm able now to use my custom command, great work, thanks,

amine2233 avatar Apr 19 '23 03:04 amine2233