Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.3k views
in Technique[技术] by (71.8m points)

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

When I do cd some-repo; git push origin master in 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.

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

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

Then waits for the child bash process to finish.

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:

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 master always 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?

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!

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).

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...