Skip to content

Commit

Permalink
Add support for specifying a particular revision for git repositories (
Browse files Browse the repository at this point in the history
  • Loading branch information
openvmp authored Dec 29, 2023
1 parent 6f91a7f commit 701343d
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/partcad/project_factory_git.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")


Expand Down Expand Up @@ -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.
Expand All @@ -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:
Expand Down

0 comments on commit 701343d

Please sign in to comment.