From 5972bd88a5465e13038f41c4e0e1f81a56e4b7fb Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Jan 24 2020 17:54:27 +0000 Subject: Enable running a command in a specific folder and return the output This way we can use the command's output and start relying on the system's git in more places. Signed-off-by: Pierre-Yves Chibon --- diff --git a/pagure/lib/repo.py b/pagure/lib/repo.py index 0fe3404..58cdb9f 100644 --- a/pagure/lib/repo.py +++ b/pagure/lib/repo.py @@ -28,10 +28,12 @@ def get_pygit2_version(): return tuple([int(i) for i in pygit2.__version__.split(".")]) -def run_command(command): +def run_command(command, cwd=None): _log.info("Running command: %s", command) try: - out = subprocess.check_output(command, stderr=subprocess.STDOUT) + out = subprocess.check_output( + command, stderr=subprocess.STDOUT, cwd=cwd + ).decode("utf-8") _log.info(" command ran successfully") _log.debug("Output: %s" % out) except subprocess.CalledProcessError as err: @@ -44,6 +46,7 @@ def run_command(command): raise pagure.exceptions.PagureException( "Did not manage to rebase this pull-request" ) + return out class PagureRepo(pygit2.Repository):