|
11 | 11 | import os |
12 | 12 | import re |
13 | 13 | import shutil |
| 14 | +from typing import Optional |
14 | 15 |
|
15 | 16 | from cfbs.utils import ( |
16 | 17 | cfbs_dir, |
@@ -148,22 +149,20 @@ def _get_git_repo_commit_sha(repo_path): |
148 | 149 | return f.read().strip() |
149 | 150 |
|
150 | 151 |
|
151 | | -def _clone_and_checkout(url, path, commit): |
| 152 | +def _clone_and_checkout(url, path, treeish): |
152 | 153 | # NOTE: If any of these shell (git) commands fail, we will exit |
153 | 154 | if not os.path.exists(os.path.join(path, ".git")): |
154 | 155 | sh("git clone --no-checkout %s %s" % (url, path)) |
155 | | - sh("git checkout " + commit, directory=path) |
| 156 | + sh("git checkout " + treeish, directory=path) |
156 | 157 |
|
157 | 158 |
|
158 | | -def clone_url_repo(repo_url: str): |
159 | | - assert repo_url.startswith(SUPPORTED_URI_SCHEMES) |
| 159 | +def clone_url_repo(repo_url: str, commit: Optional[str] = None): |
| 160 | + """Clones a Git repository at `repo_url` URL, optionally checking out the `commit` commit. |
160 | 161 |
|
161 | | - commit = None |
162 | | - if "@" in repo_url and (repo_url.rindex("@") > repo_url.rindex(".")): |
163 | | - # commit specified in the url |
164 | | - repo_url, commit = repo_url.rsplit("@", 1) |
165 | | - if not is_a_commit_hash(commit): |
166 | | - raise CFBSExitError("'%s' is not a commit reference" % commit) |
| 162 | + Returns path to the `cfbs.json` located in the cloned Git repository, and the Git commit hash. |
| 163 | + """ |
| 164 | + assert repo_url.startswith(SUPPORTED_URI_SCHEMES) |
| 165 | + assert "@" not in repo_url or (repo_url.rindex("@") < repo_url.rindex(".")) |
167 | 166 |
|
168 | 167 | downloads = os.path.join(cfbs_dir(), "downloads") |
169 | 168 |
|
|
0 commit comments