Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(toolkit): recursive repository cloning #42

Merged
merged 4 commits into from
Jan 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 27 additions & 3 deletions projects/fal/src/fal/toolkit/utils/download_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,16 @@ def clone_repository(
if local_repo_commit_hash == commit_hash and not force:
return local_repo_path
else:
if local_repo_commit_hash != commit_hash:
print(
f"Local repository '{local_repo_path}' has a different commit hash "
f"({local_repo_commit_hash}) than the one provided ({commit_hash})."
)
elif force:
print(
f"Local repository '{local_repo_path}' already exists. "
f"Forcing re-download."
)
print(f"Removing the existing repository: {local_repo_path} ")
shutil.rmtree(local_repo_path)

Expand All @@ -362,6 +372,7 @@ def clone_repository(
clone_command = [
"git",
"clone",
"--recursive",
https_url,
temp_dir_path,
]
Expand All @@ -387,6 +398,19 @@ def clone_repository(
def _get_git_revision_hash(repo_path: Path) -> str:
import subprocess

return subprocess.check_output(
["git", "rev-parse", "HEAD"], cwd=repo_path, text=True
).strip()
try:
return subprocess.check_output(
["git", "rev-parse", "HEAD"],
cwd=repo_path,
text=True,
stderr=subprocess.STDOUT,
).strip()
except subprocess.CalledProcessError as error:
if "not a git repository" in error.output:
print(f"Repository '{repo_path}' is not a git repository.")
return ""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we let the user know somehow?


print(
f"{error}\nFailed to get the commit hash of the repository '{repo_path}' ."
)
raise error
Loading