|
17 | 17 |
|
18 | 18 | import git |
19 | 19 | import yaml |
| 20 | +from cookiecutter.repository import expand_abbreviations |
20 | 21 |
|
21 | 22 | LOG_FORMAT = json.dumps( |
22 | 23 | { |
@@ -59,23 +60,33 @@ def get_context() -> dict: |
59 | 60 |
|
60 | 61 | try: |
61 | 62 | if Path(template).is_absolute(): |
62 | | - template_path = Path(template).resolve() |
| 63 | + template_path: Path = Path(template).resolve() |
63 | 64 | else: |
64 | | - output_path = Path(output).resolve() |
65 | | - template_path = output_path.joinpath(template) |
| 65 | + output_path: Path = Path(output).resolve() |
| 66 | + template_path: Path = output_path.joinpath(template) |
66 | 67 |
|
67 | | - repo = git.Repo(template_path) |
| 68 | + # IMPORTANT: If the specified template is remote (http/git/ssh) this SHOULD raise an exception. The remote logic is in the except block |
| 69 | + repo: git.Repo = git.Repo(template_path) |
68 | 70 |
|
69 | 71 | # Expect this is a local template |
70 | | - branch = str(repo.active_branch) |
71 | | - dirty = repo.is_dirty(untracked_files=True) |
| 72 | + branch: str = str(repo.active_branch) |
| 73 | + dirty: bool = repo.is_dirty(untracked_files=True) |
72 | 74 | template_commit_hash = git.cmd.Git().ls_remote(template_path, "HEAD")[:40] |
73 | 75 | except (git.exc.InvalidGitRepositoryError, git.exc.NoSuchPathError): |
74 | | - # Expect this is a remote template |
75 | | - template_repo = template |
| 76 | + # This exception handling occurs every time the template repo is remote |
| 77 | + |
| 78 | + # From https://github.com/cookiecutter/cookiecutter/blob/1b8520e7075175db4a3deae85e71081730ca7ad1/cookiecutter/config.py#L15 |
| 79 | + abbreviations: dict[str, str] = { |
| 80 | + "gh": "https://github.com/{0}.git", |
| 81 | + "gl": "https://gitlab.com/{0}.git", |
| 82 | + "bb": "https://bitbucket.org/{0}", |
| 83 | + } |
| 84 | + template_repo: str = expand_abbreviations(template, abbreviations) |
| 85 | + |
76 | 86 | # This currently assumes main until https://github.com/cookiecutter/cookiecutter/issues/1759 is resolved |
77 | | - branch = "main" |
78 | | - dirty = False |
| 87 | + branch: str = "main" |
| 88 | + dirty: bool = False |
| 89 | + |
79 | 90 | template_commit_hash = git.cmd.Git().ls_remote(template_repo, branch)[:40] |
80 | 91 |
|
81 | 92 | context: dict[ |
|
0 commit comments