Skip to content

Commit da7bd2b

Browse files
Recognize ssh:// template URLs in bundle init (#5891)
## Changes `gitUrlPrefixes` in `libs/template/resolver.go` only recognized `https://` and `git@`, which is incomplete relative to the [git URL spec](https://git-scm.com/docs/git-clone#_git_urls). This adds `ssh://` so `databricks bundle init` clones templates from SSH-transport URLs. `git://`, `http://`, and `ftp[s]://` are deliberately excluded as deprecated/insecure protocols. Also renames `IsRepoUrl` to `IsGitRepoUrl` and simplifies it to return directly on the first matching prefix. ## Why Closes #5881: SSH-transport template URLs were not recognized and fell through to the local-path reader. For non `git@` prefixed SSH URLs customers could not use the command. ## Tests Unit test `TestBundleInitIsGitRepoUrl` updated to cover the supported (`https://`, `ssh://`, `git@`) and unsupported (`git://`, `http://`, `ftp[s]://`, local paths) forms. No acceptance test exercises git-URL detection. _This PR was written by Claude Code._
1 parent f77764d commit da7bd2b

3 files changed

Lines changed: 25 additions & 12 deletions

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Recognize `ssh://` template URLs in `databricks bundle init` ([#5891](https://github.com/databricks/cli/pull/5891)).

libs/template/resolver.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,22 @@ import (
88
"github.com/databricks/cli/libs/git"
99
)
1010

11+
// See https://git-scm.com/docs/git-clone#_git_urls for the set of supported
12+
// Git URL forms. We deliberately exclude deprecated/insecure protocols (git, http, ftp[s]).
1113
var gitUrlPrefixes = []string{
1214
"https://",
15+
"ssh://",
16+
// recognize git@ without ssh:// protocol because this is very common
1317
"git@",
1418
}
1519

16-
func IsRepoUrl(url string) bool {
17-
result := false
20+
func IsGitRepoUrl(url string) bool {
1821
for _, prefix := range gitUrlPrefixes {
1922
if strings.HasPrefix(url, prefix) {
20-
result = true
21-
break
23+
return true
2224
}
2325
}
24-
return result
26+
return false
2527
}
2628

2729
// ResolveReader resolves a template path/URL to a Reader (built-in, git or local)
@@ -30,7 +32,7 @@ func ResolveReader(templatePathOrUrl, templateDir, ref string) (Reader, bool) {
3032
return tmpl.Reader, false
3133
}
3234

33-
if IsRepoUrl(templatePathOrUrl) {
35+
if IsGitRepoUrl(templatePathOrUrl) {
3436
return NewGitReader(templatePathOrUrl, ref, templateDir, git.Clone), true
3537
}
3638

libs/template/resolver_test.go

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,22 @@ func TestTemplateResolverForCustomPath(t *testing.T) {
100100
assert.Equal(t, "/config/file", tmpl.Writer.(*defaultWriter).configPath)
101101
}
102102

103-
func TestBundleInitIsRepoUrl(t *testing.T) {
104-
assert.True(t, IsRepoUrl("git@github.com:databricks/cli.git"))
105-
assert.True(t, IsRepoUrl("https://github.com/databricks/cli.git"))
106-
107-
assert.False(t, IsRepoUrl("./local"))
108-
assert.False(t, IsRepoUrl("foo"))
103+
func TestBundleInitIsGitRepoUrl(t *testing.T) {
104+
// Supported
105+
assert.True(t, IsGitRepoUrl("git@github.com:databricks/cli.git"))
106+
assert.True(t, IsGitRepoUrl("https://github.com/databricks/cli.git"))
107+
assert.True(t, IsGitRepoUrl("ssh://user@company.ghe.com/databricks/cli.git"))
108+
109+
// Unsupported
110+
assert.False(t, IsGitRepoUrl("git://github.com/databricks/cli.git"))
111+
assert.False(t, IsGitRepoUrl("http://github.com/databricks/cli.git"))
112+
assert.False(t, IsGitRepoUrl("ftp://github.com/databricks/cli.git"))
113+
assert.False(t, IsGitRepoUrl("ftps://github.com/databricks/cli.git"))
114+
115+
// Not git repos
116+
assert.False(t, IsGitRepoUrl("./local"))
117+
assert.False(t, IsGitRepoUrl("foo"))
118+
assert.False(t, IsGitRepoUrl("github.com/databricks/cli.git"))
109119
}
110120

111121
func TestResolveReader(t *testing.T) {

0 commit comments

Comments
 (0)