From 8c14b9d1aff1e877b79354ab08453f776a2ac9e6 Mon Sep 17 00:00:00 2001 From: Haibing Zhou Date: Mon, 5 Jul 2021 13:07:57 -0700 Subject: [PATCH] api/internal/git: handle .git suffix in repospec This change adds a new test case for parsing url with `.git` suffix. In that case, we should have the full url as clone spec with an empty abspath. --- api/internal/git/repospec.go | 2 +- api/internal/git/repospec_test.go | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/api/internal/git/repospec.go b/api/internal/git/repospec.go index 5a935f510..10ebb980a 100644 --- a/api/internal/git/repospec.go +++ b/api/internal/git/repospec.go @@ -125,7 +125,7 @@ func parseGitUrl(n string) ( index := strings.Index(n, gitSuffix) orgRepo = n[0:index] n = n[index+len(gitSuffix):] - if n[0] == '/' { + if len(n) > 0 && n[0] == '/' { n = n[1:] } path, gitRef, gitTimeout, gitSubmodules = peelQuery(n) diff --git a/api/internal/git/repospec_test.go b/api/internal/git/repospec_test.go index 8c9fdf604..2e4404d03 100644 --- a/api/internal/git/repospec_test.go +++ b/api/internal/git/repospec_test.go @@ -182,6 +182,12 @@ func TestNewRepoSpecFromUrl_CloneSpecs(t *testing.T) { absPath: notCloned.String(), ref: "", }, + "t12": { + input: "https://bitbucket.example.com/scm/project/repository.git", + cloneSpec: "https://bitbucket.example.com/scm/project/repository.git", + absPath: notCloned.String(), + ref: "", + }, } for tn, tc := range testcases { t.Run(tn, func(t *testing.T) {