Cygwin/Git Bizarre Terminal Issue

7,327

Solution 1

OK, I think I've found a definite solution.

The problem is that, regardless of the terminal used (puttycyg, mintty, cmd.exe), Git by default, in the absence of better configured alternatives, tries to use a "simple password prompt" (as you can read in the description of core.askpass config option).

The simple password prompt apparently only works on real UNIX, but not on Cygwin.

The solution is to install an SSH_ASKPASS compatible program for Windows and configure Git to use it.

What I did was:

  1. Install win-ssh-askpass application by unpacking and copying to C:\
  2. Download and install the Borland Delphi 5 runtime required by win-ssh-askpass (hard to come by nowadays, but found one on http://www.satsignal.eu/software/runtime.html)
  3. Configure Git to obtain passwords using win-ssh-askpass: git config --global core.askpass "C:/win_ssh_askpass.exe". Note that the EXE file has underscores in its name, not minus signs.
  4. Remember to always place your login in the URL (https://<user>@<domain>/<repository>). Otherwise, Git will ask for the login before asking for the password, using the same askpass utility. You may unknowingly input your password as the login, which will be sent to the webserwer and logged in its access log as plain text!

Now Git asks for the password using an elegant GUI window and works regardless of the terminal used :)

Solution 2

I've experienced the same issue - however in my case I am SSH'd in the Cygwin server so obviously a Win32 GUI askpass won't work.

Instead, I wrote this simple script to do the askpass. I though it could be used from regular prompts as well by getting the tty device from /bin/tty.exe but that didn't work for an unknown reason (feel free to tty yourself or look for another solution to get the tty, maybe I just got it wrong somehow).

/bin/askpass.sh:

#!/bin/bash

TTY=$SSH_TTY
[ -c "$TTY" -a -r "$TTY" -a -w "$TTY" ] \
  || { echo "Failed to open device \`$TTY'!"; exit 1; }
exec <$TTY

echo -n "$@" >$TTY
read -s P
echo >$TTY

echo $P

Make sure this script is executable and use it as your git's core.askpass setting. Since this script relies on the $SSH_TTY variable it will normally only work from SSH. You could however set $SSH_TTY in .bashrc or .bash_profile if unset; this way it should work even from a console. The following line in your rc script should do it:

[ -z "$SSH_TTY" ] && export SSH_TTY=$(/bin/tty.exe)

Solution 3

solutions above do not work for me, but I found another one.

you have to run ssh agent

just add to ~/.bashrc and restart console

SSH_ENV=$HOME/.ssh/environment



# start the ssh-agent

function start_agent {

    echo "Initializing new SSH agent..."

    # spawn ssh-agent

    /usr/bin/ssh-agent | sed 's/^echo/#echo/' > "${SSH_ENV}"

    echo succeeded

    chmod 600 "${SSH_ENV}"

    . "${SSH_ENV}" > /dev/null

    /usr/bin/ssh-add

}



if [ -f "${SSH_ENV}" ]; then

     . "${SSH_ENV}" > /dev/null

     ps -ef | grep ${SSH_AGENT_PID} | grep ssh-agent$ > /dev/null || {

        start_agent;

    }

else

    start_agent;

fi

P.S. Chrome and Opera use linebreak which isn't compatible with bash - just use another browser for copy paste

Solution 4

Question was answered already... I just would like to add how I fixed:

Checking Windows Git Bash, I could see that git set following SSH_ASKPASS

$ echo $SSH_ASKPASS
/mingw64/libexec/git-core/git-gui--askpass

So, on Cygwin, I added same variable to .bashrc

# Unconditionally export SSH_ASKPASS
export SSH_ASKPASS="/mingw64/libexec/git-core/git-gui--askpass"

or

# export SSH_ASKPASS only if git is installed
hash git 2>/dev/null && export SSH_ASKPASS="/mingw64/libexec/git-core/git-gui--askpass"

Doing this, git opens the SSH_ASKPASS from Git... I did not had to install any additional SW or create any additional script.

Hope this can help!

Solution 5

It's possible you have a metacharacter, such as &, in the URL. This would cause git to run in the background, and on a Unix system it would be stopped as soon as it tried to read from stdin. A ; would also terminate the command partway through the line, and the Ctrl-C would cause the rest of the line (a separate command) to be aborted.

It's interesting that git initializes the repo in /cygdrive/c/src/project/dev/.git/ even though you told it to use ~/src/project/dev (unless you have your home directory in a strange place). This would suggest that the git command is not seeing the rest of the command line, which is what would happen if there was a stray & or ; in the URL.

(I've had this problem lots of times with wget, although not with git.)

Try a git clone from a different repo, or using a different transport from the same repo, to see if git is messed up generally or just for this repo. You could also try putting single quotes around the URL.

Share:
7,327

Related videos on Youtube

emptyset
Author by

emptyset

Updated on September 17, 2022

Comments

  • emptyset
    emptyset over 1 year

    Alright, this is weird. First off, this is mintty running on up-to-date cygwin, with git pulled from cygwin's setup.exe. I am running zsh.

    $ git clone https://<user>@<domain>/<repository>/ ~/src/project/dev
    Initialized empty Git repository in /cygdrive/c/src/project/dev/.git/
    Password: <actual password in plain text appears>
    # Nothing happens...
    ^C
    $ <password text that I just typed>
    zsh: command not found: <same password text>
    

    What is going on here? Is this a terminal problem, a shell problem, a git problem, or a cygwin problem?

    Update: Yes, I'm running the Cygwin git version, not the Windows version:

    $ which git
    /usr/bin/git
    $ git --version
    git version 1.7.1
    $ /cygdrive/c/Program\ Files\ \(x86\)/Git/bin/git.exe --version
    git version 1.7.0.2.msysgit.0
    
  • emptyset
    emptyset almost 14 years
    ~/src is a symlink to /cygdrive/c/src (C:\src). There's no & in the URL. I'll try to clone a public git repository, but generally those won't have a password...
  • corretge
    corretge about 12 years
    thanks, run randomly, but runs :) I don't know why git don't run as expected. subversion do it fine.
  • schlamar
    schlamar about 12 years
    I can confirm this solution, works very well.
  • Eric
    Eric about 12 years
    This worked pretty well for me too. However, I had to add a redirect (1>&2) on that "Failed to open ..." message in order for it to be visible.
  • Derek Greer
    Derek Greer about 9 years
    I just ran the following and it pops a gui: git config --global core.askpass "git-gui--askpass" clone
  • vonbrand
    vonbrand over 8 years
    Why not just use ssh as a transport?