From 2c58f9ba231327b2ddb693d9a577ec3d1d33503f Mon Sep 17 00:00:00 2001 From: Mariatta Date: Wed, 6 Sep 2017 16:03:41 -0700 Subject: [PATCH] Don't `cd` if we are in CPython directory (GH-12) --- backport/tasks.py | 6 +++++- backport/util.py | 12 +++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/backport/tasks.py b/backport/tasks.py index 2e06e5f1a9695cc..2442aa57c468d37 100644 --- a/backport/tasks.py +++ b/backport/tasks.py @@ -24,10 +24,14 @@ def setup_cpython_repo(): f"git remote add upstream https://{os.environ.get('GH_AUTH')}:x-oauth-basic@github.com/python/cpython.git".split()) print("Finished setting up CPython Repo") + @app.task def backport_task(commit_hash, branch, *, issue_number, created_by, merged_by): """Backport a commit into a branch.""" - print(os.chdir("./cpython")) + if not util.is_cpython_repo(): + # cd to cpython if we're not already in it + + os.chdir('./cpython') cp = cherry_picker.CherryPicker('origin', commit_hash, [branch]) try: cp.backport() diff --git a/backport/util.py b/backport/util.py index 3d250d5181b8a42..c09e2dcd19a9b9f 100644 --- a/backport/util.py +++ b/backport/util.py @@ -1,5 +1,6 @@ import requests import os +import subprocess from gidgethub import sansio @@ -26,4 +27,13 @@ def comment_on_pr(issue_number, message): def user_login(item): - return item["user"]["login"] \ No newline at end of file + return item["user"]["login"] + + +def is_cpython_repo(): + cmd = "git log -r 7f777ed95a19224294949e1b4ce56bbffcb1fe9f" + try: + subprocess.check_output(cmd.split(), stderr=subprocess.STDOUT) + except subprocess.SubprocessError: + return False + return True \ No newline at end of file