Make git auto-svn fail if git svn fetch fails.
R=agable@chromium.org
BUG=437397
Review URL: https://codereview.chromium.org/1150353003
git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@295630 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/git_common.py b/git_common.py
index a01f8e5..2df4936 100644
--- a/git_common.py
+++ b/git_common.py
@@ -565,6 +565,28 @@
return proc.stdout
+@contextlib.contextmanager
+def run_stream_with_retcode(*cmd, **kwargs):
+ """Runs a git command as context manager yielding stdout as a PIPE.
+
+ stderr is dropped to avoid races if the process outputs to both stdout and
+ stderr.
+
+ Raises subprocess2.CalledProcessError on nonzero return code.
+ """
+ kwargs.setdefault('stderr', subprocess2.VOID)
+ kwargs.setdefault('stdout', subprocess2.PIPE)
+ cmd = (GIT_EXE, '-c', 'color.ui=never') + cmd
+ try:
+ proc = subprocess2.Popen(cmd, **kwargs)
+ yield proc.stdout
+ finally:
+ retcode = proc.wait()
+ if retcode != 0:
+ raise subprocess2.CalledProcessError(retcode, cmd, os.getcwd(),
+ None, None)
+
+
def run_with_stderr(*cmd, **kwargs):
"""Runs a git command.