bash 为什么 git 有时会在 git-credential-osxkeychain 上冻结?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15753429/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 05:03:55  来源:igfitidea点击:

Why does git freeze on git-credential-osxkeychain sometimes?

macosgitbashkeychain

提问by Dmitri Shuralyov

When I do cd some-repo; git push origin masterin my bash terminal, it doesn't ask me for username/password because I guess git has already saved that (it was so long ago that I don't remember the details of how that went down). I'm pushing to a GitHub repo as the remote origin.

当我cd some-repo; git push origin master在我的 bash 终端中进行操作时,它不会要求我输入用户名/密码,因为我猜 git 已经保存了它(很久以前我不记得它是如何发生的细节)。我正在推送到 GitHub 存储库作为远程源。

So I have a C++ program that does a fork and

所以我有一个 C++ 程序可以做一个 fork 和

execl("/bin/bash", "/bin/bash", "-c", "cd some-repo; git push origin master", (char *)0);

Then waits for the child bash process to finish.

然后等待子 bash 进程完成。

Sometimes it works just fine, but other times (seemingly randomly) it will freeze up. Looking at the running process hierarchy, I see:

有时它工作得很好,但其他时候(似乎是随机的)它会冻结。查看正在运行的进程层次结构,我看到:

MyProgram
  git
    git-remote-http
      git
        git-credential-osxkeychain

If I kill the child-most git-credential-osx process, my program resumes (because the parent-most git command finishes), with not surprising output such as:

如果我杀死最孩子的 git-credential-osx 进程,我的程序将恢复(因为最父母的 git 命令完成),输出并不奇怪,例如:

error: git-credential-osxkeychain died of signal 15
error: RPC failed; result=7, HTTP code = 0
fatal: The remote end hung up unexpectedly
fatal: The remote end hung up unexpectedly

My question: why does git push origin masteralways seem to work (without asking me for any username password or other stdin) in a bash terminal, but hangs (probably asks for something on stdin) on git-credential-osxkeychain sometimes but not other times when I run it from my C++ program?

我的问题:为什么似乎git push origin master总是在 bash 终端中工作(不要求我提供任何用户名密码或其他标准输入),但有时在 git-credential-osxkeychain 上挂起(可能要求在标准输入上输入某些内容),但在其他时候我运行时却没有它来自我的 C++ 程序?

I tried looking for man page on git-credential-osxkeychain and couldn't really find anything. Running it only prints Usage: git credential-osxkeychain <get|store|erase>which isn't self-explanatory enough for me. Thank you!

我尝试在 git-credential-osxkeychain 上查找手册页,但找不到任何内容。运行它只打印Usage: git credential-osxkeychain <get|store|erase>这对我来说不够自我解释。谢谢!

I'm running OS X 10.8.3; git version 1.7.12.4 (Apple Git-37); GNU bash, version 3.2.48(1)-release (x86_64-apple-darwin12).

我正在运行 OS X 10.8.3;git 版本 1.7.12.4 (Apple Git-37);GNU bash,版本 3.2.48(1)-release (x86_64-apple-darwin12)。

回答by John Szakmeister

Without much information, my guess is that the hanging depends on whether or not your login keychain is locked at the time. On the Mac, if the login keychain is unlocked, then the query to get your username and password can proceed unhindered. But if the keychain is locked, then then Mac OS X wants to prompt you for your login password to unlock the keychain. I suspect the dialog box is there, just hidden behind something, so you may have missed it. It'll wait for you to type in your password, effectively hanging the process.

没有太多信息,我的猜测是挂起取决于您的登录钥匙串当时是否被锁定。在 Mac 上,如果登录钥匙串已解锁,则获取用户名和密码的查询可以不受阻碍地进行。但是如果钥匙串被锁定,那么 Mac OS X 会提示您输入登录密码来解锁钥匙串。我怀疑对话框就在那里,只是隐藏在某些东西后面,所以您可能错过了它。它会等待您输入密码,从而有效地挂起该过程。

There is more information on the gitcredential infrastructure here, and more about the API (including the command line for a helper) here.

此处提供了有关gitcredential 基础结构的更多信息,此处提供了有关 API(包括帮助程序的命令行)的更多信息