Skip to content

Commit 78a4eca

Browse files
committed
fix bug: failed open when specail http port
1 parent e274b5a commit 78a4eca

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

git.go

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func GitRemotes() ([]string, error) {
3636
return git2https(uniq(result)), nil
3737
}
3838

39-
//remove duplicate string
39+
// remove duplicate string
4040
func uniq(list []string) []string {
4141
var m = make(map[string]bool)
4242
for i := range list {
@@ -49,20 +49,25 @@ func uniq(list []string) []string {
4949
return result
5050
}
5151

52-
//git ssh protocol address convert to https protocol address
53-
//$remote = $remote =~ s/\.git$//r;
54-
//$remote = $remote =~ s/^git@/https:\/\//r;
55-
//$remote = $remote =~ s/(:)([^\/])/\/$2/r;
52+
// git ssh protocol address convert to https protocol address
53+
// $remote = $remote =~ s/\.git$//r;
54+
// $remote = $remote =~ s/^git@/https:\/\//r;
55+
// $remote = $remote =~ s/(:)([^\/])/\/$2/r;
5656
func git2https(origins []string) []string {
5757
var result []string
5858
end := regexp.MustCompile(`.git$`)
5959
protocol := regexp.MustCompile(`^git@`)
6060
s := regexp.MustCompile(`(:)([^\/])`)
6161
for _, origin := range origins {
62-
r := end.ReplaceAll([]byte(origin), []byte(""))
63-
r = protocol.ReplaceAll(r, []byte("https://"))
64-
r = s.ReplaceAll(r, []byte("/$2"))
65-
result = append(result, string(r))
62+
if protocol.Match([]byte(origin)) {
63+
r := end.ReplaceAll([]byte(origin), []byte(""))
64+
r = protocol.ReplaceAll(r, []byte("https://"))
65+
r = s.ReplaceAll(r, []byte("/$2"))
66+
result = append(result, string(r))
67+
} else {
68+
result = append(result, origin)
69+
}
70+
6671
}
6772
return result
6873
}

0 commit comments

Comments
 (0)