summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosip Sokcevic <sokcevic@chromium.org>2024-09-26 21:55:10 +0000
committerLUCI <gerrit-scoped@luci-project-accounts.iam.gserviceaccount.com>2024-09-26 22:10:36 +0000
commit621de7ed127f2adb39ed1f0747383ac2afc4d075 (patch)
treed5bdd5a66932a3aa93193d01291e5ae580c3a873
parentd7ebdf56be6095338ea37bd4b52533c5bd7774e7 (diff)
downloadgit-repo-621de7ed127f2adb39ed1f0747383ac2afc4d075.tar.gz
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 <nasser.grainawi@linaro.org> Tested-by: Josip Sokcevic <sokcevic@google.com> Commit-Queue: Josip Sokcevic <sokcevic@google.com> Reviewed-by: Gavin Mak <gavinmak@google.com>
-rw-r--r--git_command.py15
-rw-r--r--project.py13
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:
313 cwd = None 313 cwd = None
314 command_name = cmdv[0] 314 command_name = cmdv[0]
315 command.append(command_name) 315 command.append(command_name)
316 # Need to use the --progress flag for fetch/clone so output will be 316
317 # displayed as by default git only does progress output if stderr is a 317 if command_name in ("fetch", "clone"):
318 # TTY. 318 env["GIT_TERMINAL_PROMPT"] = "0"
319 if sys.stderr.isatty() and command_name in ("fetch", "clone"): 319 # Need to use the --progress flag for fetch/clone so output will be
320 if "--progress" not in cmdv and "--quiet" not in cmdv: 320 # displayed as by default git only does progress output if stderr is
321 command.append("--progress") 321 # a TTY.
322 if sys.stderr.isatty():
323 if "--progress" not in cmdv and "--quiet" not in cmdv:
324 command.append("--progress")
322 command.extend(cmdv[1:]) 325 command.extend(cmdv[1:])
323 326
324 event_log = ( 327 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:
2697 ) 2697 )
2698 # Continue right away so we don't sleep as we shouldn't need to. 2698 # Continue right away so we don't sleep as we shouldn't need to.
2699 continue 2699 continue
2700 elif (
2701 ret == 128
2702 and gitcmd.stdout
2703 and "fatal: could not read Username" in gitcmd.stdout
2704 ):
2705 # User needs to be authenticated, and Git wants to prompt for
2706 # username and password.
2707 print(
2708 "git requires authentication, but repo cannot perform "
2709 "interactive authentication. Check git credentials.",
2710 file=output_redir,
2711 )
2712 break
2700 elif current_branch_only and is_sha1 and ret == 128: 2713 elif current_branch_only and is_sha1 and ret == 128:
2701 # Exit code 128 means "couldn't find the ref you asked for"; if 2714 # Exit code 128 means "couldn't find the ref you asked for"; if
2702 # we're in sha1 mode, we just tried sync'ing from the upstream 2715 # we're in sha1 mode, we just tried sync'ing from the upstream