From e6ec703eac8ac3413d7a34575aa858ae3ba83f91 Mon Sep 17 00:00:00 2001 From: simon Date: Thu, 2 Jun 2022 07:55:53 +0700 Subject: [PATCH] better clone-pull path building --- builder/monitor.py | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/builder/monitor.py b/builder/monitor.py index 1a9b436..fa0df2e 100644 --- a/builder/monitor.py +++ b/builder/monitor.py @@ -96,17 +96,13 @@ class Builder(RedisBase): def clone(self): """clone repo to destination""" print("clone repo") - clone = ["git", "clone", self.task_detail["clone"]] - pull = ["git", "pull", self.task_detail["clone"]] - os.chdir("clone") - try: - subprocess.run(clone, check=True) - except subprocess.CalledProcessError: - print("git pull instead") - os.chdir(self.task) - subprocess.run(pull, check=True) - os.chdir("../") - os.chdir("../") + repo_dir = os.path.join(self.CLONE_BASE, self.task_detail["name"]) + if os.path.exists(repo_dir): + command = ["git", "-C", repo_dir, "pull"] + else: + command = ["git", "clone", self.task_detail["clone"], repo_dir] + + subprocess.run(command, check=True) def build(self): """build the container"""