np icon indicating copy to clipboard operation
np copied to clipboard

Freezes on git activity

Open coreybutler opened this issue 8 years ago • 9 comments

I just setup a new environment and hadn't yet added my SSH keys with the ssh-agent... therefore I was being prompted for a passphrase for each git request. np hung on "Checking Prerequisites". I would expect this behavior, but it would be nice to intercept the issue and output a warning as opposed to freezing up.

coreybutler avatar Feb 07 '17 17:02 coreybutler

Yes. I experienced the same when I reinstalled my computer a couple of months ago. Even better would be to actually letting the user enter their password. Depends on https://github.com/SamVerschueren/listr/issues/32.

sindresorhus avatar Feb 07 '17 19:02 sindresorhus

Yes this is something I really need to work on. The thing is that I don't know of a way to detect if it's waiting for input. So any help on that part would be more then welcome.

SamVerschueren avatar Feb 07 '17 19:02 SamVerschueren

I've never been able to put together what I feel is a truly "clean" solution for this, but there are inelegant approaches I've used with some success. Sometimes monitoring stdout of the child process can provide enough info to determine if the user has been prompted with a question. This is pretty dependent on the commands being run, the OS, and it's not really accounting for stdin at all. However; if you can anticipate the possible responses from the child process, it might work situationally.

Another inelegant but potentially useful solution is to use a timeout. Each task could be monitored. If progress is not made or if the step is not completed in ___ seconds, display an informational message of "possible" things happening or things the user should check for. It's not a perfect solution, but it provides a starting point for the user to begin their own investigation, and it eliminates some of the guesswork.

coreybutler avatar Feb 08 '17 15:02 coreybutler

Calling my personal stdin expert → @Qix-, Any thoughts?

sindresorhus avatar Feb 13 '17 08:02 sindresorhus

Before I dive into this, just one remark:

@coreybutler: I've never been able to put together what I feel is a truly "clean" solution for this, but there are inelegant approaches I've used with some success.

In the TTY world, there is no such thing as a clean solution. 🌮


There is no way (that I know of) to determine if a child subprocess is waiting for input either in raw mode or otherwise. However, you can tell the child process "hey I don't have any input for you" by closing that particular file descriptor on the child.

However, processes can choose to ignore that and re-open stdin. Git is one of those.

Git has a specific environment variable, though, to make it fail instead of hang: GIT_TERMINAL_PROMPT=0. This will cause it to exit with a non-zero code if it can't automatically authenticate.

Something else to try (I haven't tried it myself) is to either continuously close the subprocess' stdin handle, or alternatively close it and then detect if it opens it again (not sure if that's possible).

If it is possible, you might be able to fake-detect if the child process is waiting for input.

The last solution, IMO the simplest solution, is to read from Git's stderr handle (or maybe it's stdout, not sure) and detect the output Username: and forward that to the user and allow them to type their credentials in.

Not sure if any of that helps :o

Qix- avatar Feb 13 '17 08:02 Qix-

In the TTY world, there is no such thing as a clean solution. 🌮

Just one remark: s/TTY/programming/


Thanks @Qix- :)

sindresorhus avatar Feb 13 '17 09:02 sindresorhus

Just adding the correct hung: Prerequisite check for people looking for this issue. Would be neat, to add this feature.

gabrielstuff avatar May 20 '17 13:05 gabrielstuff

For people with the same issue, here is what I've done:

vim ~/.ssh/config

Add

Host *
    UseKeychain yes

Then pushing to a repo and returning bakc to np works.

gabrielstuff avatar May 20 '17 13:05 gabrielstuff

To kind of stack on what @gabrielstuff said, if you're on Windows, but using HTTP, I would suggest using wincred to store your credentials. See this stackoverflow thread: https://stackoverflow.com/a/11889392/222955

gonzofish avatar May 25 '17 17:05 gonzofish