summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMike Frysinger <vapier@google.com>2025-03-27 17:06:11 -0400
committerLUCI <gerrit-scoped@luci-project-accounts.iam.gserviceaccount.com>2025-04-01 17:28:26 -0700
commitdc8185f2a9af53fd91fef160313564ad1abf827f (patch)
tree0b94d8250fd5e25087ba112145fd469517bff59c
parent59b81c84ded4e2312b2b554d22a51dca89825bc3 (diff)
downloadgit-repo-dc8185f2a9af53fd91fef160313564ad1abf827f.tar.gz
launcher: change RunError to subprocess.CalledProcessError
Since we require Python 3.6 now in the launcher, swap out our custom RunError class for the standard subprocess one. Change-Id: Id0ca17c40e22ece03e06366a263ad340963f979d Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/464401 Commit-Queue: Mike Frysinger <vapier@google.com> Reviewed-by: Scott Lee <ddoman@google.com> Tested-by: Mike Frysinger <vapier@google.com>
-rwxr-xr-xrepo13
-rw-r--r--tests/test_wrapper.py2
2 files changed, 6 insertions, 9 deletions
diff --git a/repo b/repo
index 21085688..782afb6e 100755
--- a/repo
+++ b/repo
@@ -482,11 +482,6 @@ def InitParser(parser):
482 return parser 482 return parser
483 483
484 484
485# This is a poor replacement for subprocess.run until we require Python 3.6+.
486class RunError(Exception):
487 """Error when running a command failed."""
488
489
490def run_command(cmd, **kwargs): 485def run_command(cmd, **kwargs):
491 """Run |cmd| and return its output.""" 486 """Run |cmd| and return its output."""
492 check = kwargs.pop("check", False) 487 check = kwargs.pop("check", False)
@@ -544,7 +539,8 @@ def run_command(cmd, **kwargs):
544 539
545 _print_output("stdout", ret.stdout) 540 _print_output("stdout", ret.stdout)
546 _print_output("stderr", ret.stderr) 541 _print_output("stderr", ret.stderr)
547 raise RunError(ret) 542 # This will raise subprocess.CalledProcessError for us.
543 ret.check_returncode()
548 544
549 return ret 545 return ret
550 546
@@ -668,7 +664,7 @@ def run_git(*args, **kwargs):
668 file=sys.stderr, 664 file=sys.stderr,
669 ) 665 )
670 sys.exit(1) 666 sys.exit(1)
671 except RunError: 667 except subprocess.CalledProcessError:
672 raise CloneFailure() 668 raise CloneFailure()
673 669
674 670
@@ -850,7 +846,8 @@ def _GetRepoConfig(name):
850 f"repo: error: git {' '.join(cmd)} failed:\n{ret.stderr}", 846 f"repo: error: git {' '.join(cmd)} failed:\n{ret.stderr}",
851 file=sys.stderr, 847 file=sys.stderr,
852 ) 848 )
853 raise RunError() 849 # This will raise subprocess.CalledProcessError for us.
850 ret.check_returncode()
854 851
855 852
856def _InitHttp(): 853def _InitHttp():
diff --git a/tests/test_wrapper.py b/tests/test_wrapper.py
index 8bb5eb28..77ceda8f 100644
--- a/tests/test_wrapper.py
+++ b/tests/test_wrapper.py
@@ -126,7 +126,7 @@ class RunCommand(RepoWrapperTestCase):
126 self.wrapper.run_command(["true"], check=False) 126 self.wrapper.run_command(["true"], check=False)
127 self.wrapper.run_command(["true"], check=True) 127 self.wrapper.run_command(["true"], check=True)
128 self.wrapper.run_command(["false"], check=False) 128 self.wrapper.run_command(["false"], check=False)
129 with self.assertRaises(self.wrapper.RunError): 129 with self.assertRaises(subprocess.CalledProcessError):
130 self.wrapper.run_command(["false"], check=True) 130 self.wrapper.run_command(["false"], check=True)
131 131
132 132