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

Already on GitHub? Sign in to your account

Detect if git asks for username and ask the user for it. #433

Merged
merged 2 commits into from Jul 14, 2012

Conversation

Projects
None yet
4 participants
Contributor

ruediger commented Jun 24, 2012

If http is used as protocol (e.g. the new default on github) then git
might ask for a username during push operations. Currently this
results in the process hanging. This patch adds a magit-username' function similar tomagit-password' and modifies
`magit-process-filter' to call the function.

Signed-off-by: Rüdiger Sonderfeld ruediger@c-plusplus.de

@ruediger ruediger Detect if git asks for username and ask the user for it.
If http is used as protocol (e.g. the new default on github) then git
might ask for a username during push operations. Currently this
results in the process hanging. This patch adds a `magit-username'
function similar to `magit-password' and modifies
`magit-process-filter' to call the function.

Signed-off-by: Rüdiger Sonderfeld <ruediger@c-plusplus.de>
981feb5

It will ask me for username now, but wont' ask for password.

After enter username, the magit-process buffer will hang and shows:

$ git --no-pager push -v origin master:refs/heads/master
Pushing to https://github.com/RenWenshan/wenshan-compiler.git
Username for 'https://github.com': Password for 'https://renws1990@gmail.com@github.com':

Any suggestion?

@ruediger ruediger magit-password: Added regex to detect "Password for '.*'".
The string is used if a password for http is asked.

Signed-off-by: Rüdiger Sonderfeld <ruediger@c-plusplus.de>
94c71f4
Contributor

ruediger commented Jun 29, 2012

The change should fix the issue.

that works, thank you very much

@sigma sigma merged commit 94c71f4 into magit:master Jul 14, 2012

This does not work for me with git version 1.7.4.1 for github.
The remote url is of the form: https://github.com/username/project.git.
Git prompt is only "Username:".
So I had to modify the function (imitating magit-password) as below:

(defun magit-username (proc string)
"Checks if git asks for a username and ask the user for it."
(let (ask)
(cond ((or (string-match "^Username for '(.*)':" string))
(setq ask (format "Username for '%s': "
(match-string 1 string))))
((string-match "^[uU]sername:" string)
(setq ask "Username:")))
(when ask
(process-send-string proc
(concat
(read-string ask
nil nil (user-login-name))
"\n")))))

UPDATE:
Another workaround is to edit the .git/config file to specify the remote url as follows:
url = https://username@github.org/username/project.git

Then git skips the username prompt and directly asks for password.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment