[git retry] Fix Git wrapper fallthrough.
Currently, when the Infra Git wrapper is installed in PATH and a user
calls "git retry", the "git_retry.py" script is supposed to ignore the
request and fall through to the underlying command, relying on the Git
wrapper to handle retries.
However, Git apparently prepends its own executable path to PATH when it
is called, preventing the Git wrapper from being invoked the second time
and removing retries altogether.
We circumvent this by removing Git's new PATH influence when falling
through.
BUG=chromium:721450
TEST=local
- Ran locally before and after patch, confirmed that after
successfully retries throgh the wrapper.
R=agable@chromium.org, iannucci@chromium.org
Change-Id: Iae3d7a8bf805a5ba2bf827b06006a990d94e96d9
Reviewed-on: https://chromium-review.googlesource.com/506374
Reviewed-by: Robbie Iannucci <iannucci@chromium.org>
Commit-Queue: Daniel Jacques <dnj@chromium.org>
diff --git a/git_retry.py b/git_retry.py
index c153e12..bc3ce08 100755
--- a/git_retry.py
+++ b/git_retry.py
@@ -122,7 +122,15 @@
# If we're using the Infra Git wrapper, do nothing here.
# https://chromium.googlesource.com/infra/infra/+/master/go/src/infra/tools/git
if 'INFRA_GIT_WRAPPER' in os.environ:
- return subprocess.call([GIT_EXE] + args)
+ # Remove Git's execution path from PATH so that our call-through re-invokes
+ # the Git wrapper.
+ # See crbug.com/721450
+ env = os.environ.copy()
+ git_exec = subprocess.check_output([GIT_EXE, '--exec-path']).strip()
+ env['PATH'] = os.pathsep.join([
+ elem for elem in env.get('PATH', '').split(os.pathsep)
+ if elem != git_exec])
+ return subprocess.call([GIT_EXE] + args, env=env)
parser = optparse.OptionParser()
parser.disable_interspersed_args()