From 621de7ed127f2adb39ed1f0747383ac2afc4d075 Mon Sep 17 00:00:00 2001 From: Josip Sokcevic Date: Thu, 26 Sep 2024 21:55:10 +0000 Subject: [PATCH] Disable git terminal prompt during fetch/clone git fetch operation may prompt user to enter username and password. This won't be visible to user when repo sync operation since stdout and stderr are redirected. If that happens, user may think repo is doing work and likely won't realize it's stuck on user's input. This patch disables prompt for clone and fetch operations, and repo will fail fast. R=gavinmak@google.com Bug: b/368644181 Change-Id: I2efa88ae66067587a00678eda155d861034b9127 Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/438001 Reviewed-by: Nasser Grainawi Tested-by: Josip Sokcevic Commit-Queue: Josip Sokcevic Reviewed-by: Gavin Mak --- git_command.py | 15 +++++++++------ project.py | 13 +++++++++++++ 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/git_command.py b/git_command.py index 1ec7c3ed..55216b1c 100644 --- a/git_command.py +++ b/git_command.py @@ -313,12 +313,15 @@ class GitCommand: cwd = None command_name = cmdv[0] command.append(command_name) - # Need to use the --progress flag for fetch/clone so output will be - # displayed as by default git only does progress output if stderr is a - # TTY. - if sys.stderr.isatty() and command_name in ("fetch", "clone"): - if "--progress" not in cmdv and "--quiet" not in cmdv: - command.append("--progress") + + if command_name in ("fetch", "clone"): + env["GIT_TERMINAL_PROMPT"] = "0" + # Need to use the --progress flag for fetch/clone so output will be + # displayed as by default git only does progress output if stderr is + # a TTY. + if sys.stderr.isatty(): + if "--progress" not in cmdv and "--quiet" not in cmdv: + command.append("--progress") command.extend(cmdv[1:]) event_log = ( diff --git a/project.py b/project.py index dda01331..b281863b 100644 --- a/project.py +++ b/project.py @@ -2697,6 +2697,19 @@ class Project: ) # Continue right away so we don't sleep as we shouldn't need to. continue + elif ( + ret == 128 + and gitcmd.stdout + and "fatal: could not read Username" in gitcmd.stdout + ): + # User needs to be authenticated, and Git wants to prompt for + # username and password. + print( + "git requires authentication, but repo cannot perform " + "interactive authentication. Check git credentials.", + file=output_redir, + ) + break elif current_branch_only and is_sha1 and ret == 128: # Exit code 128 means "couldn't find the ref you asked for"; if # we're in sha1 mode, we just tried sync'ing from the upstream