From 80586d98b934b2e4d85699e850b392a00c816a49 Mon Sep 17 00:00:00 2001 From: Roman Kuzmenko Date: Thu, 28 Dec 2023 14:12:37 -0800 Subject: [PATCH] Add support for specifying a particular revision for git repositories --- src/partcad/project_factory_git.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/partcad/project_factory_git.py b/src/partcad/project_factory_git.py index 8fe7b322..d53d445e 100644 --- a/src/partcad/project_factory_git.py +++ b/src/partcad/project_factory_git.py @@ -17,6 +17,7 @@ class GitImportConfiguration: def __init__(self): self.import_config_url = self.config_obj.get("url") + self.import_revision = self.config_obj.get("revision") self.import_rel_path = self.config_obj.get("relPath") @@ -52,6 +53,8 @@ def _clone_or_update_repo(self, repo_url, cache_dir=None): # Generate a unique identifier for the repository based on its URL. repo_hash = hashlib.sha256(repo_url.encode()).hexdigest() + if self.import_revision is not None: + repo_hash += "-" + self.import_revision cache_path = os.path.join(cache_dir, repo_hash) # Check if the repository is already cached. @@ -61,9 +64,12 @@ def _clone_or_update_repo(self, repo_url, cache_dir=None): repo = Repo(cache_path) origin = repo.remote("origin") before = repo.active_branch.commit - origin.pull() + if self.import_revision is None: + origin.pull() + else: + origin.fetch() + repo.git.checkout(self.import_revision, force=True) after = repo.active_branch.commit - # repo.head.checkout(after, force=True) if before != after: print("\nUpdated the GIT repo: %s" % self.import_config_url) except Exception as e: