Skip to content

Commit 0a6b1fa

Browse files
committed
feature: support git:// protocol (#1339)
Signed-off-by: leo <[email protected]>
1 parent 71b90a8 commit 0a6b1fa

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/Models/Remote.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ public partial class Remote
88
{
99
[GeneratedRegex(@"^https?://([-a-zA-Z0-9:%._\+~#=]+@)?[-a-zA-Z0-9:%._\+~#=]{1,256}(\.[a-zA-Z0-9()]{1,6})?(:[0-9]{1,5})?\b(/[-a-zA-Z0-9()@:%_\+.~#?&=]+)+(\.git)?$")]
1010
private static partial Regex REG_HTTPS();
11+
[GeneratedRegex(@"^git://([-a-zA-Z0-9:%._\+~#=]+@)?[-a-zA-Z0-9:%._\+~#=]{1,256}(\.[a-zA-Z0-9()]{1,6})?(:[0-9]{1,5})?\b(/[-a-zA-Z0-9()@:%_\+.~#?&=]+)+(\.git)?$")]
12+
private static partial Regex REG_GIT();
1113
[GeneratedRegex(@"^[\w\-]+@[\w\.\-]+(\:[0-9]+)?:([a-zA-z0-9~%][\w\-\./~%]*)?[a-zA-Z0-9](\.git)?$")]
1214
private static partial Regex REG_SSH1();
1315
[GeneratedRegex(@"^ssh://([\w\-]+@)?[\w\.\-]+(\:[0-9]+)?/([a-zA-z0-9~%][\w\-\./~%]*)?[a-zA-Z0-9](\.git)?$")]
@@ -18,6 +20,7 @@ public partial class Remote
1820

1921
private static readonly Regex[] URL_FORMATS = [
2022
REG_HTTPS(),
23+
REG_GIT(),
2124
REG_SSH1(),
2225
REG_SSH2(),
2326
];
@@ -30,13 +33,10 @@ public static bool IsSSH(string url)
3033
if (string.IsNullOrWhiteSpace(url))
3134
return false;
3235

33-
for (int i = 1; i < URL_FORMATS.Length; i++)
34-
{
35-
if (URL_FORMATS[i].IsMatch(url))
36-
return true;
37-
}
36+
if (REG_SSH1().IsMatch(url))
37+
return true;
3838

39-
return false;
39+
return REG_SSH2().IsMatch(url);
4040
}
4141

4242
public static bool IsValidURL(string url)

0 commit comments

Comments
 (0)