Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(536)

Unified Diff: git_common.py

Issue 1150353003: Make git auto-svn fail if git svn fetch fails. (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/depot_tools.git@master
Patch Set: + Tests. Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « git_auto_svn.py ('k') | tests/git_common_test.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: git_common.py
diff --git a/git_common.py b/git_common.py
index 6b21050b22b87575ca192d55ddb117fcdb3710c6..1aa1227547fd314623bd5985cbabbaaeca78f5b1 100644
--- a/git_common.py
+++ b/git_common.py
@@ -565,6 +565,28 @@ def run_stream(*cmd, **kwargs):
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.
« no previous file with comments | « git_auto_svn.py ('k') | tests/git_common_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698