13
13
14
14
GIT_PREFIX = ("git@" , "git://" , "git+" )
15
15
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
+ )
19
22
20
23
21
24
def is_git_repo_root (path : Path ) -> bool :
@@ -36,6 +39,8 @@ def is_git_bundle(path: Path) -> bool:
36
39
37
40
38
41
def get_repo (url : str ) -> OptStr :
42
+ for pattern , replacement in REPLACEMENTS :
43
+ url = re .sub (pattern , replacement , url )
39
44
url_path = Path (url )
40
45
if not (
41
46
url .endswith (GIT_POSTFIX )
@@ -47,9 +52,6 @@ def get_repo(url: str) -> OptStr:
47
52
48
53
if url .startswith ("git+" ):
49
54
url = url [4 :]
50
-
51
- url = re .sub (RE_GITHUB , "https://github.com/" , url )
52
- url = re .sub (RE_GITLAB , "https://gitlab.com/" , url )
53
55
return url
54
56
55
57
0 commit comments