Skip to content

Commit 6a48b55

Browse files
committed
feat: use git[+subprotocol] pattern
See helm/community#321 Signed-off-by: Dominykas Blyžė <[email protected]>
1 parent df08b4d commit 6a48b55

File tree

6 files changed

+38
-16
lines changed

6 files changed

+38
-16
lines changed

internal/gitutil/gitutil.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,14 @@ package gitutil
1818

1919
import (
2020
"os"
21+
"regexp"
2122
"strings"
2223

2324
"github.com/Masterminds/vcs"
2425
)
2526

27+
var gitRepositoryURLRe = regexp.MustCompile("^git(\\+\\w+)?://")
28+
2629
// HasGitReference returns true if a git repository contains a specified ref (branch/tag)
2730
func HasGitReference(gitRepo, ref, repoName string) (bool, error) {
2831
local, err := os.MkdirTemp("", repoName)
@@ -44,10 +47,10 @@ func HasGitReference(gitRepo, ref, repoName string) (bool, error) {
4447

4548
// IsGitRepository determines whether a URL is to be treated as a git repository URL
4649
func IsGitRepository(url string) bool {
47-
return strings.HasPrefix(url, "git://")
50+
return gitRepositoryURLRe.MatchString(url)
4851
}
4952

5053
// RepositoryURLToGitURL converts a repository URL into a URL that `git clone` could consume
5154
func RepositoryURLToGitURL(url string) string {
52-
return strings.TrimPrefix(url, "git://")
55+
return strings.TrimPrefix(url, "git+")
5356
}

internal/gitutil/gitutil_test.go

+18-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func TestIsGitUrl(t *testing.T) {
2828
}{
2929
{"oci://example.com/example/chart", false},
3030
{"git://example.com/example/chart", true},
31-
{"git://https://example.com/example/chart", true},
31+
{"git+https://example.com/example/chart", true},
3232
}
3333

3434
for _, test := range tests {
@@ -37,3 +37,20 @@ func TestIsGitUrl(t *testing.T) {
3737
}
3838
}
3939
}
40+
41+
func TestRepositoryURLToGitURL(t *testing.T) {
42+
// Test table: Given url, RepositoryURLToGitURL should return expect.
43+
tests := []struct {
44+
url string
45+
expect string
46+
}{
47+
{"git://example.com/example/chart", "git://example.com/example/chart"},
48+
{"git+https://example.com/example/chart", "https://example.com/example/chart"},
49+
}
50+
51+
for _, test := range tests {
52+
if RepositoryURLToGitURL(test.url) != test.expect {
53+
t.Errorf("Expected %s for %s", test.expect, test.url)
54+
}
55+
}
56+
}

internal/resolver/resolver_test.go

+8-8
Original file line numberDiff line numberDiff line change
@@ -149,47 +149,47 @@ func TestResolve(t *testing.T) {
149149
{
150150
name: "repo from git https url",
151151
req: []*chart.Dependency{
152-
{Name: "gitdependencyok", Repository: "git://https://github.com/helm/helmchart.git", Version: "1.0.0"},
152+
{Name: "gitdependencyok", Repository: "git+https://github.com/helm/helmchart.git", Version: "1.0.0"},
153153
},
154154
expect: &chart.Lock{
155155
Dependencies: []*chart.Dependency{
156-
{Name: "gitdependencyok", Repository: "git://https://github.com/helm/helmchart.git", Version: "1.0.0"},
156+
{Name: "gitdependencyok", Repository: "git+https://github.com/helm/helmchart.git", Version: "1.0.0"},
157157
},
158158
},
159159
err: false,
160160
},
161161
{
162162
name: "repo from git https url",
163163
req: []*chart.Dependency{
164-
{Name: "gitdependencyerror", Repository: "git://https://github.com/helm/helmchart.git", Version: "2.0.0"},
164+
{Name: "gitdependencyerror", Repository: "git+https://github.com/helm/helmchart.git", Version: "2.0.0"},
165165
},
166166
expect: &chart.Lock{
167167
Dependencies: []*chart.Dependency{
168-
{Name: "gitdependencyerror", Repository: "git://https://github.com/helm/helmchart.git", Version: "2.0.0"},
168+
{Name: "gitdependencyerror", Repository: "git+https://github.com/helm/helmchart.git", Version: "2.0.0"},
169169
},
170170
},
171171
err: true,
172172
},
173173
{
174174
name: "repo from git ssh url",
175175
req: []*chart.Dependency{
176-
{Name: "gitdependency", Repository: "git://git@github.com:helm/helmchart.git", Version: "1.0.0"},
176+
{Name: "gitdependency", Repository: "git://github.com:helm/helmchart.git", Version: "1.0.0"},
177177
},
178178
expect: &chart.Lock{
179179
Dependencies: []*chart.Dependency{
180-
{Name: "gitdependency", Repository: "git://git@github.com:helm/helmchart.git", Version: "1.0.0"},
180+
{Name: "gitdependency", Repository: "git://github.com:helm/helmchart.git", Version: "1.0.0"},
181181
},
182182
},
183183
err: false,
184184
},
185185
{
186186
name: "repo from git ssh url",
187187
req: []*chart.Dependency{
188-
{Name: "gitdependencyerror", Repository: "git://git@github.com:helm/helmchart.git", Version: "2.0.0"},
188+
{Name: "gitdependencyerror", Repository: "git://github.com:helm/helmchart.git", Version: "2.0.0"},
189189
},
190190
expect: &chart.Lock{
191191
Dependencies: []*chart.Dependency{
192-
{Name: "gitdependencyerror", Repository: "git://git@github.com:helm/helmchart.git", Version: "2.0.0"},
192+
{Name: "gitdependencyerror", Repository: "git://github.com:helm/helmchart.git", Version: "2.0.0"},
193193
},
194194
},
195195
err: true,

pkg/downloader/chart_downloader_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ func TestResolveChartRef(t *testing.T) {
4040
{name: "full URL", ref: "http://example.com/foo-1.2.3.tgz", expect: "http://example.com/foo-1.2.3.tgz"},
4141
{name: "full URL, HTTPS", ref: "https://example.com/foo-1.2.3.tgz", expect: "https://example.com/foo-1.2.3.tgz"},
4242
{name: "full URL, with authentication", ref: "http://username:[email protected]/foo-1.2.3.tgz", expect: "http://username:[email protected]/foo-1.2.3.tgz"},
43-
{name: "helmchart", ref: "git://https://github.com/helmchart/helmchart.git", expect: "https://github.com/helmchart/helmchart.git"},
43+
{name: "helmchart", ref: "git+https://github.com/helmchart/helmchart.git", expect: "https://github.com/helmchart/helmchart.git"},
44+
{name: "helmchart", ref: "git://github.com/helmchart/helmchart.git", expect: "git://github.com/helmchart/helmchart.git"},
4445
{name: "reference, testing repo", ref: "testing/alpine", expect: "http://example.com/alpine-1.2.3.tgz"},
4546
{name: "reference, version, testing repo", ref: "testing/alpine", version: "0.2.0", expect: "http://example.com/alpine-0.2.0.tgz"},
4647
{name: "reference, version, malformed repo", ref: "malformed/alpine", version: "1.2.3", expect: "http://dl.example.com/alpine-1.2.3.tgz"},

pkg/downloader/manager_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ func TestFindChartURL(t *testing.T) {
8686
}{
8787
{name: "alpine", version: "0.1.0", repoURL: "http://example.com/charts", expectChurl: "https://charts.helm.sh/stable/alpine-0.1.0.tgz", expectUserName: "", expectPassword: "", expectInsecureSkipTLSVerify: false, expectPasscredentialsall: false},
8888
{name: "tlsfoo", version: "1.2.3", repoURL: "https://example-https-insecureskiptlsverify.com", expectChurl: "https://example.com/tlsfoo-1.2.3.tgz", expectUserName: "", expectPassword: "", expectInsecureSkipTLSVerify: true, expectPasscredentialsall: false},
89-
{name: "helm-test", version: "master", repoURL: "git://https://github.com/rally25rs/helm-test-chart.git", expectChurl: "git://https://github.com/rally25rs/helm-test-chart.git", expectUserName: "", expectPassword: "", expectInsecureSkipTLSVerify: false, expectPasscredentialsall: false},
89+
{name: "helm-test", version: "master", repoURL: "git+https://github.com/rally25rs/helm-test-chart.git", expectChurl: "git+https://github.com/rally25rs/helm-test-chart.git", expectUserName: "", expectPassword: "", expectInsecureSkipTLSVerify: false, expectPasscredentialsall: false},
9090
}
9191
for _, tt := range tests {
9292
churl, username, password, insecureSkipTLSVerify, passcredentialsall, _, _, _, err := m.findChartURL(tt.name, tt.version, tt.repoURL, repos)
@@ -177,9 +177,9 @@ func TestGetRepoNames(t *testing.T) {
177177
{
178178
name: "repo from git url",
179179
req: []*chart.Dependency{
180-
{Name: "local-dep", Repository: "git://https://github.com/git/git"},
180+
{Name: "local-dep", Repository: "git+https://github.com/git/git"},
181181
},
182-
expect: map[string]string{"local-dep": "git://https://github.com/git/git"},
182+
expect: map[string]string{"local-dep": "git+https://github.com/git/git"},
183183
},
184184
}
185185

pkg/getter/gitgetter.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,11 @@ package getter
1818
import (
1919
"bytes"
2020
"fmt"
21-
"helm.sh/helm/v3/pkg/gitutil"
2221
"os"
2322
"path/filepath"
2423

24+
"helm.sh/helm/v3/pkg/gitutil"
25+
2526
"github.com/Masterminds/vcs"
2627

2728
"helm.sh/helm/v3/internal/fileutil"

0 commit comments

Comments
 (0)