Skip to content

Commit 183928e

Browse files
authored
Merge pull request #5023 from KnVerey/issue4998
Fix regression with scp-style urls with only one path element
2 parents 87c428e + c0e2030 commit 183928e

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

api/internal/git/repospec.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,8 +370,9 @@ func trimPrefixIgnoreCase(s, prefix string) (string, bool) {
370370
func findPathSeparator(hostPath string, acceptSCP bool) int {
371371
sepIndex := strings.Index(hostPath, pathSeparator)
372372
if acceptSCP {
373+
colonIndex := strings.Index(hostPath, ":")
373374
// The colon acts as a delimiter in scp-style ssh URLs only if not prefixed by '/'.
374-
if colonIndex := strings.Index(hostPath, ":"); colonIndex > 0 && colonIndex < sepIndex {
375+
if sepIndex == -1 || (colonIndex > 0 && colonIndex < sepIndex) {
375376
sepIndex = colonIndex
376377
}
377378
}

api/internal/git/repospec_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -659,6 +659,26 @@ func TestNewRepoSpecFromUrl_Smoke(t *testing.T) {
659659
RepoPath: "kubernetes-sigs/kustomize",
660660
},
661661
},
662+
{
663+
name: "scp format gist url",
664+
input: "git@gist.github.com:bc7947cb727d7f9217e7862d961a1ffd.git",
665+
cloneSpec: "git@gist.github.com:bc7947cb727d7f9217e7862d961a1ffd.git",
666+
absPath: notCloned.String(),
667+
repoSpec: RepoSpec{
668+
Host: "git@gist.github.com:",
669+
RepoPath: "bc7947cb727d7f9217e7862d961a1ffd.git",
670+
},
671+
},
672+
{
673+
name: "https gist url",
674+
input: "https://gist.github.com/bc7947cb727d7f9217e7862d961a1ffd.git",
675+
cloneSpec: "https://gist.github.com/bc7947cb727d7f9217e7862d961a1ffd.git",
676+
absPath: notCloned.String(),
677+
repoSpec: RepoSpec{
678+
Host: "https://gist.github.com/",
679+
RepoPath: "bc7947cb727d7f9217e7862d961a1ffd.git",
680+
},
681+
},
662682
}
663683
for _, tc := range testcases {
664684
t.Run(tc.name, func(t *testing.T) {

0 commit comments

Comments
 (0)