Skip to content

Commit f678f4a

Browse files
authored
Merge pull request #120 from dasuken/master
Implement getAbsoluteUrl function to abort the difference in incoming url when use -t option
2 parents 6de6066 + de91d76 commit f678f4a

File tree

3 files changed

+55
-3
lines changed

3 files changed

+55
-3
lines changed

pkg/cgapp/git.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@ package cgapp
66

77
import (
88
"fmt"
9+
"net/url"
910
"os"
1011
"path/filepath"
12+
"strings"
1113

1214
"github.com/go-git/go-git/v5"
1315
)
@@ -30,7 +32,7 @@ func GitClone(templateType, templateURL string) error {
3032
folder,
3133
false,
3234
&git.CloneOptions{
33-
URL: fmt.Sprintf("https://%s", templateURL),
35+
URL: getAbsoluteURL(templateURL),
3436
},
3537
)
3638
if errPlainClone != nil {
@@ -44,3 +46,14 @@ func GitClone(templateType, templateURL string) error {
4446

4547
return nil
4648
}
49+
50+
func getAbsoluteURL(templateURL string) string {
51+
templateURL = strings.TrimSpace(templateURL)
52+
u, _ := url.Parse(templateURL)
53+
54+
if len(u.Scheme) == 0 {
55+
u.Scheme = "https"
56+
}
57+
58+
return u.String()
59+
}

pkg/cgapp/git_test.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,44 @@ func TestGitClone(t *testing.T) {
5959
}
6060
}
6161
}
62+
63+
func Test_getAbsoluteURL(t *testing.T) {
64+
type args struct {
65+
templateURL string
66+
}
67+
tests := []struct {
68+
name string
69+
args args
70+
want string
71+
}{
72+
{
73+
"successfully get absolute url from url with scheme",
74+
args{
75+
templateURL: "https://github.com/create-go-app/net_http-go-template",
76+
},
77+
"https://github.com/create-go-app/net_http-go-template",
78+
},
79+
{
80+
"successfully get absolute url from url without scheme",
81+
args{
82+
templateURL: "github.com/create-go-app/net_http-go-template",
83+
},
84+
"https://github.com/create-go-app/net_http-go-template",
85+
},
86+
{
87+
"successfully get absolute url from url starting space",
88+
args{
89+
templateURL: " github.com/create-go-app/net_http-go-template",
90+
},
91+
"https://github.com/create-go-app/net_http-go-template",
92+
},
93+
}
94+
95+
for _, tt := range tests {
96+
t.Run(tt.name, func(t *testing.T) {
97+
if got := getAbsoluteURL(tt.args.templateURL); got != tt.want {
98+
t.Errorf("getAbsoluteURL() = %v, want %v", got, tt.want)
99+
}
100+
})
101+
}
102+
}

pkg/registry/defaults.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,15 +111,13 @@ var (
111111
Name: "backend",
112112
Prompt: &survey.Input{
113113
Message: "Enter URL to the custom backend repository:",
114-
Help: "No need to specify `http://` or `https://` protocol.",
115114
},
116115
Validate: survey.Required,
117116
},
118117
{
119118
Name: "frontend",
120119
Prompt: &survey.Input{
121120
Message: "Enter URL to the custom frontend repository:",
122-
Help: "No need to specify `http://` or `https://` protocol.",
123121
Default: "none",
124122
},
125123
},

0 commit comments

Comments
 (0)