@@ -36,7 +36,7 @@ func GitRemotes() ([]string, error) {
3636 return git2https (uniq (result )), nil
3737}
3838
39- //remove duplicate string
39+ // remove duplicate string
4040func 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;
5656func 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