Skip to content

Commit fe0ffb3

Browse files
authored
Merge pull request #167 from Tecnativa/fix-shortcodes
Fix shortcode without .git suffix
2 parents 7049a62 + c7eddc1 commit fe0ffb3

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

copier/vcs.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,12 @@
1313

1414
GIT_PREFIX = ("git@", "git://", "git+")
1515
GIT_POSTFIX = (".git",)
16-
17-
RE_GITHUB = re.compile(r"^gh:/?")
18-
RE_GITLAB = re.compile(r"^gl:/?")
16+
REPLACEMENTS = (
17+
(re.compile(r"^gh:/?(.*\.git)$"), r"https://github.com/\1"),
18+
(re.compile(r"^gh:/?(.*)$"), r"https://github.com/\1.git"),
19+
(re.compile(r"^gl:/?(.*\.git)$"), r"https://gitlab.com/\1"),
20+
(re.compile(r"^gl:/?(.*)$"), r"https://gitlab.com/\1.git"),
21+
)
1922

2023

2124
def is_git_repo_root(path: Path) -> bool:
@@ -36,6 +39,8 @@ def is_git_bundle(path: Path) -> bool:
3639

3740

3841
def get_repo(url: str) -> OptStr:
42+
for pattern, replacement in REPLACEMENTS:
43+
url = re.sub(pattern, replacement, url)
3944
url_path = Path(url)
4045
if not (
4146
url.endswith(GIT_POSTFIX)
@@ -47,9 +52,6 @@ def get_repo(url: str) -> OptStr:
4752

4853
if url.startswith("git+"):
4954
url = url[4:]
50-
51-
url = re.sub(RE_GITHUB, "https://github.com/", url)
52-
url = re.sub(RE_GITLAB, "https://gitlab.com/", url)
5355
return url
5456

5557

tests/test_vcs.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@ def test_get_repo():
2020
get("gh:/jpscaletti/copier.git") == "https://github.com/jpscaletti/copier.git"
2121
)
2222
assert get("gh:jpscaletti/copier.git") == "https://github.com/jpscaletti/copier.git"
23-
2423
assert get("gl:jpscaletti/copier.git") == "https://gitlab.com/jpscaletti/copier.git"
24+
assert get("gh:jpscaletti/copier") == "https://github.com/jpscaletti/copier.git"
25+
assert get("gl:jpscaletti/copier") == "https://gitlab.com/jpscaletti/copier.git"
2526

2627
assert (
2728
get("git+https://git.myproject.org/MyProject")

0 commit comments

Comments
 (0)