diff --git a/cmd/jb/install_test.go b/cmd/jb/install_test.go index daf33a0..90df289 100644 --- a/cmd/jb/install_test.go +++ b/cmd/jb/install_test.go @@ -60,8 +60,8 @@ func testInstallCommandWithJsonnetHome(t *testing.T, jsonnetHome string) { Name: "OneURL", URIs: []string{"github.com/jsonnet-bundler/jsonnet-bundler@v0.1.0"}, ExpectedCode: 0, - ExpectedJsonnetFile: []byte(`{"version": 1, "dependencies": [{"source": {"git": {"remote": "https://github.com/jsonnet-bundler/jsonnet-bundler", "subdir": ""}}, "version": "v0.1.0"}], "legacyImports": true}`), - ExpectedJsonnetLockFile: []byte(`{"version": 1, "dependencies": [{"source": {"git": {"remote": "https://github.com/jsonnet-bundler/jsonnet-bundler", "subdir": ""}}, "version": "080f157c7fb85ad0281ea78f6c641eaa570a582f", "sum": "W1uI550rQ66axRpPXA2EZDquyPg/5PHZlvUz1NEzefg="}], "legacyImports": false}`), + ExpectedJsonnetFile: []byte(`{"version": 1, "dependencies": [{"source": {"git": {"remote": "https://github.com/jsonnet-bundler/jsonnet-bundler.git", "subdir": ""}}, "version": "v0.1.0"}], "legacyImports": true}`), + ExpectedJsonnetLockFile: []byte(`{"version": 1, "dependencies": [{"source": {"git": {"remote": "https://github.com/jsonnet-bundler/jsonnet-bundler.git", "subdir": ""}}, "version": "080f157c7fb85ad0281ea78f6c641eaa570a582f", "sum": "W1uI550rQ66axRpPXA2EZDquyPg/5PHZlvUz1NEzefg="}], "legacyImports": false}`), }, { Name: "Local", @@ -74,8 +74,8 @@ func testInstallCommandWithJsonnetHome(t *testing.T, jsonnetHome string) { Name: "single", URIs: []string{"github.com/grafana/loki/production/ksonnet/loki@bd4d516262c107a0bde7a962fa2b1e567a2c21e5"}, ExpectedCode: 0, - ExpectedJsonnetFile: []byte(`{"version":1,"dependencies":[{"source":{"git":{"remote":"https://github.com/grafana/loki","subdir":"production/ksonnet/loki"}},"version":"bd4d516262c107a0bde7a962fa2b1e567a2c21e5","single":true}],"legacyImports":true}`), - ExpectedJsonnetLockFile: []byte(`{"version":1,"dependencies":[{"source":{"git":{"remote":"https://github.com/grafana/loki","subdir":"production/ksonnet/loki"}},"version":"bd4d516262c107a0bde7a962fa2b1e567a2c21e5","sum":"ExovUKXmZ4KwJAv/q8ZwNW9BdIZlrxmoGrne7aR64wo=","single":true}],"legacyImports":false}`), + ExpectedJsonnetFile: []byte(`{"version":1,"dependencies":[{"source":{"git":{"remote":"https://github.com/grafana/loki.git","subdir":"production/ksonnet/loki"}},"version":"bd4d516262c107a0bde7a962fa2b1e567a2c21e5","single":true}],"legacyImports":true}`), + ExpectedJsonnetLockFile: []byte(`{"version":1,"dependencies":[{"source":{"git":{"remote":"https://github.com/grafana/loki.git","subdir":"production/ksonnet/loki"}},"version":"bd4d516262c107a0bde7a962fa2b1e567a2c21e5","sum":"ExovUKXmZ4KwJAv/q8ZwNW9BdIZlrxmoGrne7aR64wo=","single":true}],"legacyImports":false}`), single: true, }, } diff --git a/cmd/jb/update_test.go b/cmd/jb/update_test.go index 3dd5e32..9625fe7 100644 --- a/cmd/jb/update_test.go +++ b/cmd/jb/update_test.go @@ -102,24 +102,24 @@ func TestUpdate(t *testing.T) { name: "simple", uris: []string{}, // no uris before: &RepoState{ - File: `{"version":1,"dependencies":[{"source":{"git":{"remote":"https://github.com/jsonnet-bundler/frozen-lib","subdir":""}},"version":"master"}],"legacyImports":true}`, - Lock: `{"version":1,"dependencies":[{"source":{"git":{"remote":"https://github.com/jsonnet-bundler/frozen-lib","subdir":""}},"version":"9f40207f668e382b706e1822f2d46ce2cd0a57cc","sum":"qUJDskVRtmkTms2udvFpLi1t5YKVbGmMSyiZnPjXsMo="}],"legacyImports":false}`, + File: `{"version":1,"dependencies":[{"source":{"git":{"remote":"https://github.com/jsonnet-bundler/frozen-lib.git","subdir":""}},"version":"master"}],"legacyImports":true}`, + Lock: `{"version":1,"dependencies":[{"source":{"git":{"remote":"https://github.com/jsonnet-bundler/frozen-lib.git","subdir":""}},"version":"9f40207f668e382b706e1822f2d46ce2cd0a57cc","sum":"qUJDskVRtmkTms2udvFpLi1t5YKVbGmMSyiZnPjXsMo="}],"legacyImports":false}`, }, after: &RepoState{ - File: `{"version":1,"dependencies":[{"source":{"git":{"remote":"https://github.com/jsonnet-bundler/frozen-lib","subdir":""}},"version":"master"}],"legacyImports":true}`, - Lock: `{"version":1,"dependencies":[{"source":{"git":{"remote":"https://github.com/jsonnet-bundler/frozen-lib","subdir":""}},"version":"ed7c1aff9e10d3b42fb130446d495f1c769ecd7b","sum":"OraOcUvDIx9Eikaihi8XsRNRsVehO75Ek35im/jYoSA="}],"legacyImports":false}`, + File: `{"version":1,"dependencies":[{"source":{"git":{"remote":"https://github.com/jsonnet-bundler/frozen-lib.git","subdir":""}},"version":"master"}],"legacyImports":true}`, + Lock: `{"version":1,"dependencies":[{"source":{"git":{"remote":"https://github.com/jsonnet-bundler/frozen-lib.git","subdir":""}},"version":"ed7c1aff9e10d3b42fb130446d495f1c769ecd7b","sum":"OraOcUvDIx9Eikaihi8XsRNRsVehO75Ek35im/jYoSA="}],"legacyImports":false}`, }, }, { name: "single", uris: []string{"github.com/jsonnet-bundler/frozen-lib"}, before: &RepoState{ - File: `{"version":1,"dependencies":[{"source":{"git":{"remote":"https://github.com/grafana/jsonnet-libs","subdir":"ksonnet-util"}},"version":"master"},{"source":{"git":{"remote":"https://github.com/jsonnet-bundler/frozen-lib","subdir":""}},"version":"master"}],"legacyImports":true}`, - Lock: `{"version":1,"dependencies":[{"source":{"git":{"remote":"https://github.com/grafana/jsonnet-libs","subdir":"ksonnet-util"}},"version":"610b00d219d0a6f3d833dd44e4bb0deda2429da0","sum":"XdIrw3m7I8fJ3CL9eR8LtuYcanf2QK78n4H4OBBOADc="},{"source":{"git":{"remote":"https://github.com/jsonnet-bundler/frozen-lib","subdir":""}},"version":"9f40207f668e382b706e1822f2d46ce2cd0a57cc","sum":"qUJDskVRtmkTms2udvFpLi1t5YKVbGmMSyiZnPjXsMo="}],"legacyImports":false}`, + File: `{"version":1,"dependencies":[{"source":{"git":{"remote":"https://github.com/grafana/jsonnet-libs.git","subdir":"ksonnet-util"}},"version":"master"},{"source":{"git":{"remote":"https://github.com/jsonnet-bundler/frozen-lib.git","subdir":""}},"version":"master"}],"legacyImports":true}`, + Lock: `{"version":1,"dependencies":[{"source":{"git":{"remote":"https://github.com/grafana/jsonnet-libs.git","subdir":"ksonnet-util"}},"version":"610b00d219d0a6f3d833dd44e4bb0deda2429da0","sum":"XdIrw3m7I8fJ3CL9eR8LtuYcanf2QK78n4H4OBBOADc="},{"source":{"git":{"remote":"https://github.com/jsonnet-bundler/frozen-lib.git","subdir":""}},"version":"9f40207f668e382b706e1822f2d46ce2cd0a57cc","sum":"qUJDskVRtmkTms2udvFpLi1t5YKVbGmMSyiZnPjXsMo="}],"legacyImports":false}`, }, after: &RepoState{ - File: `{"version":1,"dependencies":[{"source":{"git":{"remote":"https://github.com/grafana/jsonnet-libs","subdir":"ksonnet-util"}},"version":"master"},{"source":{"git":{"remote":"https://github.com/jsonnet-bundler/frozen-lib","subdir":""}},"version":"master"}],"legacyImports":true}`, - Lock: `{"version":1,"dependencies":[{"source":{"git":{"remote":"https://github.com/grafana/jsonnet-libs","subdir":"ksonnet-util"}},"version":"610b00d219d0a6f3d833dd44e4bb0deda2429da0","sum":"XdIrw3m7I8fJ3CL9eR8LtuYcanf2QK78n4H4OBBOADc="},{"source":{"git":{"remote":"https://github.com/jsonnet-bundler/frozen-lib","subdir":""}},"version":"ed7c1aff9e10d3b42fb130446d495f1c769ecd7b","sum":"OraOcUvDIx9Eikaihi8XsRNRsVehO75Ek35im/jYoSA="}],"legacyImports":false}`, + File: `{"version":1,"dependencies":[{"source":{"git":{"remote":"https://github.com/grafana/jsonnet-libs.git","subdir":"ksonnet-util"}},"version":"master"},{"source":{"git":{"remote":"https://github.com/jsonnet-bundler/frozen-lib.git","subdir":""}},"version":"master"}],"legacyImports":true}`, + Lock: `{"version":1,"dependencies":[{"source":{"git":{"remote":"https://github.com/grafana/jsonnet-libs.git","subdir":"ksonnet-util"}},"version":"610b00d219d0a6f3d833dd44e4bb0deda2429da0","sum":"XdIrw3m7I8fJ3CL9eR8LtuYcanf2QK78n4H4OBBOADc="},{"source":{"git":{"remote":"https://github.com/jsonnet-bundler/frozen-lib.git","subdir":""}},"version":"ed7c1aff9e10d3b42fb130446d495f1c769ecd7b","sum":"OraOcUvDIx9Eikaihi8XsRNRsVehO75Ek35im/jYoSA="}],"legacyImports":false}`, }, }, } diff --git a/pkg/git.go b/pkg/git.go index 1cd0910..c11d399 100644 --- a/pkg/git.go +++ b/pkg/git.go @@ -183,7 +183,7 @@ func (p *GitPackage) Install(ctx context.Context, name, dir, version string) (st defer os.RemoveAll(tmpDir) // Optimization for GitHub sources: download a tarball archive of the requested - // version instead of cloning the entire repository. + // version instead of cloning the entire isGitHubRemote, err := regexp.MatchString(`^(https|ssh)://github\.com/.+$`, p.Source.Remote()) if isGitHubRemote { // Let git ls-remote decide if "version" is a ref or a commit SHA in the unlikely @@ -197,7 +197,7 @@ func (p *GitPackage) Install(ctx context.Context, name, dir, version string) (st commitSha = version } - archiveUrl := fmt.Sprintf("%s/archive/%s.tar.gz", p.Source.Remote(), commitSha) + archiveUrl := fmt.Sprintf("%s/archive/%s.tar.gz", strings.TrimSuffix(p.Source.Remote(), ".git"), commitSha) archiveFilepath := fmt.Sprintf("%s.tar.gz", tmpDir) defer os.Remove(archiveFilepath) diff --git a/spec/v1/deps/git.go b/spec/v1/deps/git.go index f3d0543..9d0567d 100644 --- a/spec/v1/deps/git.go +++ b/spec/v1/deps/git.go @@ -80,18 +80,18 @@ func (gs *Git) UnmarshalJSON(data []byte) error { // Name returns the repository in a go-like format (example.com/user/repo/subdir) func (gs *Git) Name() string { - return fmt.Sprintf("%s/%s/%s%s", gs.Host, gs.User, gs.Repo, gs.Subdir) + return fmt.Sprintf("%s/%s/%s%s", gs.Host, gs.User, strings.TrimSuffix(gs.Repo, ".git"), gs.Subdir) } // LegacyName returns the last element of the packages path // example: github.com/ksonnet/ksonnet-lib/ksonnet.beta.4 becomes ksonnet.beta.4 func (gs *Git) LegacyName() string { - return filepath.Base(gs.Repo + gs.Subdir) + return filepath.Base(strings.TrimSuffix(gs.Repo, ".git") + gs.Subdir) } var gitProtoFmts = map[string]string{ GitSchemeSSH: GitSchemeSSH + "%s/%s/%s.git", - GitSchemeHTTPS: GitSchemeHTTPS + "%s/%s/%s", + GitSchemeHTTPS: GitSchemeHTTPS + "%s/%s/%s.git", } // Remote returns a remote string that can be passed to git diff --git a/spec/v1/deps/git_test.go b/spec/v1/deps/git_test.go index fe2ed73..7cbbdcd 100644 --- a/spec/v1/deps/git_test.go +++ b/spec/v1/deps/git_test.go @@ -53,7 +53,7 @@ func TestParseGit(t *testing.T) { Subdir: "/ksonnet.beta.3", }}, }, - wantRemote: "https://github.com/ksonnet/ksonnet-lib", + wantRemote: "https://github.com/ksonnet/ksonnet-lib.git", }, { name: "ssh.ssh", @@ -82,7 +82,7 @@ func TestParseGit(t *testing.T) { }, }, }, - wantRemote: "https://example.com/foo/bar", + wantRemote: "https://example.com/foo/bar.git", }, { name: "ValidGitNoScheme", @@ -99,7 +99,7 @@ func TestParseGit(t *testing.T) { }, }, }, - wantRemote: "https://example.com/foo/bar", + wantRemote: "https://example.com/foo/bar.git", }, { name: "ValidGitPath", @@ -116,7 +116,7 @@ func TestParseGit(t *testing.T) { }, }, }, - wantRemote: "https://example.com/foo/bar", + wantRemote: "https://example.com/foo/bar.git", }, { name: "ValidGitVersion", @@ -133,7 +133,7 @@ func TestParseGit(t *testing.T) { }, }, }, - wantRemote: "https://example.com/foo/bar", + wantRemote: "https://example.com/foo/bar.git", }, { name: "ValidGitPathVersion", @@ -150,7 +150,7 @@ func TestParseGit(t *testing.T) { }, }, }, - wantRemote: "https://example.com/foo/bar", + wantRemote: "https://example.com/foo/bar.git", }, { name: "ValidGitSubdomain", @@ -167,7 +167,7 @@ func TestParseGit(t *testing.T) { }, }, }, - wantRemote: "https://git.example.com/foo/bar", + wantRemote: "https://git.example.com/foo/bar.git", }, { name: "ValidGitSubgroups", @@ -184,7 +184,7 @@ func TestParseGit(t *testing.T) { }, }, }, - wantRemote: "https://example.com/group/subgroup/repository", + wantRemote: "https://example.com/group/subgroup/repository.git", }, { name: "ValidGitSubgroupSubDir", @@ -201,7 +201,7 @@ func TestParseGit(t *testing.T) { }, }, }, - wantRemote: "https://example.com/group/subgroup/repository", + wantRemote: "https://example.com/group/subgroup/repository.git", }, } diff --git a/spec/v1/spec_test.go b/spec/v1/spec_test.go index 73c3353..cf07f43 100644 --- a/spec/v1/spec_test.go +++ b/spec/v1/spec_test.go @@ -30,7 +30,7 @@ const jsonJF = `{ { "source": { "git": { - "remote": "https://github.com/grafana/jsonnet-libs", + "remote": "https://github.com/grafana/jsonnet-libs.git", "subdir": "grafana-builder" } }, @@ -41,7 +41,7 @@ const jsonJF = `{ "name": "prometheus", "source": { "git": { - "remote": "https://github.com/prometheus/prometheus", + "remote": "https://github.com/prometheus/prometheus.git", "subdir": "documentation/prometheus-mixin" } },