Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

start-ssh-agent.cmd doesn't execute @CALL cmd %* at the end of the script #3975

Open
1 task done
AnastaZIuk opened this issue Aug 7, 2022 · 8 comments
Open
1 task done
Labels

Comments

@AnastaZIuk
Copy link

AnastaZIuk commented Aug 7, 2022

  • I was not able to find an open or closed issue matching what I'm seeing

Setup

I'm using Git for windows, 64-bit

$ git --version --build-options

git version 2.37.1.windows.1
cpu: x86_64
built from commit: 323a69709944b193bb5cee81ff09fe9a4a686df5
sizeof-long: 4
sizeof-size_t: 8
shell-path: /bin/sh
feature: fsmonitor--daemon
  • Which version of Windows are you running? Vista, 7, 8, 10? Is it 32-bit or 64-bit?
    I'm running windows 11, 64-bit
$ cmd.exe /c ver

Microsoft Windows [Version 10.0.22000.795]
  • What options did you set as part of the installation? Or did you choose the
    defaults?

    defaults

# One of the following:
> type "C:\Program Files\Git\etc\install-options.txt"
> type "C:\Program Files (x86)\Git\etc\install-options.txt"
> type "%USERPROFILE%\AppData\Local\Programs\Git\etc\install-options.txt"
> type "$env:USERPROFILE\AppData\Local\Programs\Git\etc\install-options.txt"
$ cat /etc/install-options.txt

Editor Option: CustomEditor
Custom Editor Path: C:\Program Files\Notepad++\notepad++.exe
Default Branch Option:  
Path Option: Cmd
SSH Option: OpenSSH
Tortoise Option: false
CURL Option: OpenSSL
CRLF Option: CRLFAlways
Bash Terminal Option: MinTTY
Git Pull Behavior Option: Merge
Use Credential Manager: Enabled
Performance Tweaks FSCache: Enabled
Enable Symlinks: Disabled
Enable Pseudo Console Support: Disabled
Enable FSMonitor: Disabled
  • Any other interesting things about your environment that might be related
    to the issue you're seeing?

    I don't think so

Details

  • Which terminal/shell are you running Git from? e.g Bash/CMD/PowerShell/other

CMD

   cd "C:\Program Files\Git\cmd"
   ~~cmd~~ start-ssh-agent.exe /k echo "test"
  • What did you expect to occur after running these commands?

it should perform ssh initialization and at the end if there is no fail it should execute @CALL cmd %* so in my case cmd /k echo "test"

  • What actually happened instead?

nothing executed because there is a typo,

instead of doing

@IF NOT ERRORLEVEL 1 @(
    @CALL cmd %*
)

it should be

@IF NOT !ERRORLEVEL! == 1 @(
    @CALL cmd %*
)
  • If the problem was occurring with a specific repository, can you provide the
    URL to that repository to help us with testing?

I don't know the repository I should look into

@dscho
Copy link
Member

dscho commented Aug 8, 2022

cd "C:\Program Files\Git\cmd"
cmd start-ssh-agent.exe /k echo "test"

This is the output when I try it here:

C:\Users\me>cd "C:\Program Files\Git\cmd"

C:\Program Files\Git\cmd> cmd start-ssh-agent.exe /k echo "test"
"test"

C:\Program Files\Git\cmd>

In other words: it works as expected here, without the indicated patch. Maybe this has something to do with delayed expansion? But I see that the script does enable that.

Color me puzzled.

@dscho dscho added the unclear label Aug 8, 2022
@AnastaZIuk
Copy link
Author

indeed it works for windows powershell, but it doesn't work for windows cmd
image

@AnastaZIuk
Copy link
Author

cd "C:\Program Files\Git\cmd"
cmd start-ssh-agent.exe /k echo "test"

This is the output when I try it here:

C:\Users\me>cd "C:\Program Files\Git\cmd"

C:\Program Files\Git\cmd> cmd start-ssh-agent.exe /k echo "test"
"test"

C:\Program Files\Git\cmd>

In other words: it works as expected here, without the indicated patch. Maybe this has something to do with delayed expansion? But I see that the script does enable that.

Color me puzzled.

and after the patch it works for both

@dscho
Copy link
Member

dscho commented Aug 8, 2022

but it doesn't work for windows cmd

I tried this in CMD and in PowerShell, and it works for me in both. I am not opposed to accepting a PR with the patch (you will want to modify this file), but I want to understand first why it is needed.

@dscho
Copy link
Member

dscho commented Aug 8, 2022

It's hard to quote parts of a screenshot, so I won't. Pro-tip: paste text as text, not as a picture, in the future.

The thing about the "Found" line is that I do not get it, and when I run dir %TEMP%\ssh-??????* I also don't get any hit.

Even funnier: I do not get the SSH_AGENT_PID variable, either, so maybe something is going fundamentally wrong here.

@AnastaZIuk
Copy link
Author

AnastaZIuk commented Aug 8, 2022

It's hard to quote parts of a screenshot, so I won't. Pro-tip: paste text as text, not as a picture, in the future.

oh right, sorry

well I can see that this script uses almost everywhere delayed expansion or variable expansion, and in this line https://github.com/git-for-windows/MINGW-packages/blob/05e0ebb4a53a6d58aa49c57a4a7040f149533473/mingw-w64-git/start-ssh-agent.cmd#L83 I created issue for it seems the syntax is incorrect? https://ss64.com/nt/delayedexpansion.html I'm not an expert in batch/cmd scripting, but this line simply doesn't work in my cmd

@dscho
Copy link
Member

dscho commented Aug 8, 2022

this line simply doesn't work in my cmd

The concern I have is that it might actually work as designed and that something in the command preceding it goes wrong, and we would only paper over that.

@mfriedrich74
Copy link

mfriedrich74 commented Aug 8, 2022 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants