Skip to content

Commit

Permalink
git-credential: disable prompt when not attached to a tty
Browse files Browse the repository at this point in the history
  • Loading branch information
pmrowla committed Apr 18, 2023
1 parent 885a03d commit ed83c57
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/scmrepo/git/credentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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)
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit ed83c57

Please sign in to comment.