From ed83c57db122fdd21d61dba8d6697620a5c690e7 Mon Sep 17 00:00:00 2001 From: Peter Rowlands Date: Tue, 18 Apr 2023 15:28:31 +0900 Subject: [PATCH] git-credential: disable prompt when not attached to a tty --- src/scmrepo/git/credentials.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/scmrepo/git/credentials.py b/src/scmrepo/git/credentials.py index 5bbc9c62..61485ef9 100644 --- a/src/scmrepo/git/credentials.py +++ b/src/scmrepo/git/credentials.py @@ -283,6 +283,8 @@ def _input_tty(prompt: str = "Username: ") -> str: from contextlib import ExitStack if os.name == "nt": + if not sys.stdin.isatty(): + raise EOFError return input(prompt) with ExitStack() as stack: @@ -297,6 +299,8 @@ def _input_tty(prompt: str = "Username: ") -> str: except OSError: stack.close() # fallback to default input() + if not sys.stdin.isatty(): + raise return input(prompt) try: stream.write(prompt) @@ -365,10 +369,13 @@ def get( except KeyError: pass if interactive: - if self.askpass: - return self._get_interactive(credential, self.askpass.input) - if not os.environ.get("GIT_TERMINAL_PROMPT") == "0": - return self._get_interactive(credential, _input_tty, getpass) + try: + if self.askpass: + return self._get_interactive(credential, self.askpass.input) + if not os.environ.get("GIT_TERMINAL_PROMPT") == "0": + return self._get_interactive(credential, _input_tty, getpass) + except (EOFError, OSError): + pass raise CredentialNotFoundError("No matching credentials") def _get_interactive(