Skip to content

Commit

Permalink
Merge pull request #167 from Tecnativa/fix-shortcodes
Browse files Browse the repository at this point in the history
Fix shortcode without .git suffix
  • Loading branch information
pykong authored Mar 25, 2020
2 parents 7049a62 + c7eddc1 commit fe0ffb3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
14 changes: 8 additions & 6 deletions copier/vcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,12 @@

GIT_PREFIX = ("git@", "git://", "git+")
GIT_POSTFIX = (".git",)

RE_GITHUB = re.compile(r"^gh:/?")
RE_GITLAB = re.compile(r"^gl:/?")
REPLACEMENTS = (
(re.compile(r"^gh:/?(.*\.git)$"), r"https://github.com/\1"),
(re.compile(r"^gh:/?(.*)$"), r"https://github.com/\1.git"),
(re.compile(r"^gl:/?(.*\.git)$"), r"https://gitlab.com/\1"),
(re.compile(r"^gl:/?(.*)$"), r"https://gitlab.com/\1.git"),
)


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


def get_repo(url: str) -> OptStr:
for pattern, replacement in REPLACEMENTS:
url = re.sub(pattern, replacement, url)
url_path = Path(url)
if not (
url.endswith(GIT_POSTFIX)
Expand All @@ -47,9 +52,6 @@ def get_repo(url: str) -> OptStr:

if url.startswith("git+"):
url = url[4:]

url = re.sub(RE_GITHUB, "https://github.com/", url)
url = re.sub(RE_GITLAB, "https://gitlab.com/", url)
return url


Expand Down
3 changes: 2 additions & 1 deletion tests/test_vcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ def test_get_repo():
get("gh:/jpscaletti/copier.git") == "https://github.com/jpscaletti/copier.git"
)
assert get("gh:jpscaletti/copier.git") == "https://github.com/jpscaletti/copier.git"

assert get("gl:jpscaletti/copier.git") == "https://gitlab.com/jpscaletti/copier.git"
assert get("gh:jpscaletti/copier") == "https://github.com/jpscaletti/copier.git"
assert get("gl:jpscaletti/copier") == "https://gitlab.com/jpscaletti/copier.git"

assert (
get("git+https://git.myproject.org/MyProject")
Expand Down

0 comments on commit fe0ffb3

Please sign in to comment.