diff --git a/pkg/git/git.go b/pkg/git/git.go index 12b01ed62..18c3a770d 100644 --- a/pkg/git/git.go +++ b/pkg/git/git.go @@ -21,10 +21,10 @@ const ( ) var ( - branchRegEx = regexp.MustCompile(`^([^@]*(?:git@)?[^@/]+/[^@/]+/?[^@/]+)@([a-zA-Z0-9\./\-\_]+)$`) - commitRegEx = regexp.MustCompile(`^([^@]*(?:git@)?[^@/]+/[^@]+)` + regexp.QuoteMeta(CommitDelimiter) + `([a-zA-Z0-9]+)$`) - prReferenceRegEx = regexp.MustCompile(`^([^@]*(?:git@)?[^@/]+/[^@]+)@(` + PullRequestReference + `)$`) - subPathRegEx = regexp.MustCompile(`^([^@]*(?:git@)?[^@/]+/[^@]+)` + regexp.QuoteMeta(SubPathDelimiter) + `([a-zA-Z0-9\./\-\_]+)$`) + branchRegEx = regexp.MustCompile(`^([^@]*(?:git@)?@?[^@/]+/[^@/]+/?[^@/]+)@([a-zA-Z0-9\./\-\_]+)$`) + commitRegEx = regexp.MustCompile(`^([^@]*(?:git@)?@?[^@/]+/[^@]+)` + regexp.QuoteMeta(CommitDelimiter) + `([a-zA-Z0-9]+)$`) + prReferenceRegEx = regexp.MustCompile(`^([^@]*(?:git@)?@?[^@/]+/[^@]+)@(` + PullRequestReference + `)$`) + subPathRegEx = regexp.MustCompile(`^([^@]*(?:git@)?@?[^@/]+/[^@]+)` + regexp.QuoteMeta(SubPathDelimiter) + `([a-zA-Z0-9\./\-\_]+)$`) ) func CommandContext(ctx context.Context, args ...string) *exec.Cmd { diff --git a/pkg/git/git_test.go b/pkg/git/git_test.go index 5c997037e..91855cd05 100644 --- a/pkg/git/git_test.go +++ b/pkg/git/git_test.go @@ -151,6 +151,14 @@ func TestNormalizeRepository(t *testing.T) { expectedCommit: "", expectedSubpath: "/test/path", }, + { + in: "https://my_prefix@github.com/loft-sh/devpod.git@test-branch", + expectedRepo: "https://my_prefix@github.com/loft-sh/devpod.git", + expectedPRReference: "", + expectedBranch: "test-branch", + expectedCommit: "", + expectedSubpath: "", + }, } for _, testCase := range testCases {