Skip to content

Commit

Permalink
Fix regression with scp-style urls with only one path element
Browse files Browse the repository at this point in the history
  • Loading branch information
KnVerey committed Feb 2, 2023
1 parent 87c428e commit c0e2030
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
3 changes: 2 additions & 1 deletion api/internal/git/repospec.go
Original file line number Diff line number Diff line change
Expand Up @@ -370,8 +370,9 @@ func trimPrefixIgnoreCase(s, prefix string) (string, bool) {
func findPathSeparator(hostPath string, acceptSCP bool) int {
sepIndex := strings.Index(hostPath, pathSeparator)
if acceptSCP {
colonIndex := strings.Index(hostPath, ":")
// The colon acts as a delimiter in scp-style ssh URLs only if not prefixed by '/'.
if colonIndex := strings.Index(hostPath, ":"); colonIndex > 0 && colonIndex < sepIndex {
if sepIndex == -1 || (colonIndex > 0 && colonIndex < sepIndex) {
sepIndex = colonIndex
}
}
Expand Down
20 changes: 20 additions & 0 deletions api/internal/git/repospec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,26 @@ func TestNewRepoSpecFromUrl_Smoke(t *testing.T) {
RepoPath: "kubernetes-sigs/kustomize",
},
},
{
name: "scp format gist url",
input: "git@gist.github.com:bc7947cb727d7f9217e7862d961a1ffd.git",
cloneSpec: "git@gist.github.com:bc7947cb727d7f9217e7862d961a1ffd.git",
absPath: notCloned.String(),
repoSpec: RepoSpec{
Host: "git@gist.github.com:",
RepoPath: "bc7947cb727d7f9217e7862d961a1ffd.git",
},
},
{
name: "https gist url",
input: "https://gist.github.com/bc7947cb727d7f9217e7862d961a1ffd.git",
cloneSpec: "https://gist.github.com/bc7947cb727d7f9217e7862d961a1ffd.git",
absPath: notCloned.String(),
repoSpec: RepoSpec{
Host: "https://gist.github.com/",
RepoPath: "bc7947cb727d7f9217e7862d961a1ffd.git",
},
},
}
for _, tc := range testcases {
t.Run(tc.name, func(t *testing.T) {
Expand Down

0 comments on commit c0e2030

Please sign in to comment.