From 3297cdf8bb4d530c6c3bdc2111dac112b892fdf9 Mon Sep 17 00:00:00 2001 From: Alexander Egorenkov Date: Fri, 2 Oct 2020 13:43:43 +0200 Subject: pkg/vcs: support git URL starting with file:/// For use inside a Docker container e.g. Signed-off-by: Alexander Egorenkov --- pkg/vcs/vcs.go | 8 ++++++-- pkg/vcs/vcs_test.go | 1 + 2 files changed, 7 insertions(+), 2 deletions(-) (limited to 'pkg') diff --git a/pkg/vcs/vcs.go b/pkg/vcs/vcs.go index 4f1887549..a7c1c0ed5 100644 --- a/pkg/vcs/vcs.go +++ b/pkg/vcs/vcs.go @@ -213,7 +213,9 @@ func Patch(dir string, patch []byte) error { // CheckRepoAddress does a best-effort approximate check of a git repo address. func CheckRepoAddress(repo string) bool { - return gitRepoRe.MatchString(repo) || gitSSHRepoRe.MatchString(repo) + return gitLocalRepoRe.MatchString(repo) || + gitRemoteRepoRe.MatchString(repo) || + gitSSHRepoRe.MatchString(repo) } // CheckBranch does a best-effort approximate check of a git branch name. @@ -236,7 +238,9 @@ func runSandboxed(dir, command string, args ...string) ([]byte, error) { var ( // nolint: lll - gitRepoRe = regexp.MustCompile(`^(git|ssh|http|https|ftp|ftps)://[a-zA-Z0-9-_]+(\.[a-zA-Z0-9-_]+)+(:[0-9]+)?(/[a-zA-Z0-9-_./]+)?(/)?$`) + gitLocalRepoRe = regexp.MustCompile(`^file:///[a-zA-Z0-9-_./]+(/)?$`) + // nolint: lll + gitRemoteRepoRe = regexp.MustCompile(`^(git|ssh|http|https|ftp|ftps)://[a-zA-Z0-9-_]+(\.[a-zA-Z0-9-_]+)+(:[0-9]+)?(/[a-zA-Z0-9-_./]+)?(/)?$`) // nolint: lll gitSSHRepoRe = regexp.MustCompile(`^(git|ssh|http|https|ftp|ftps)@[a-zA-Z0-9-_]+(\.[a-zA-Z0-9-_]+)+(:[a-zA-Z0-9-_]+)?(/[a-zA-Z0-9-_./]+)?(/)?$`) gitBranchRe = regexp.MustCompile("^[a-zA-Z0-9-_/.]{2,200}$") diff --git a/pkg/vcs/vcs_test.go b/pkg/vcs/vcs_test.go index 7cfb7347a..5900ca046 100644 --- a/pkg/vcs/vcs_test.go +++ b/pkg/vcs/vcs_test.go @@ -37,6 +37,7 @@ func TestCheckRepoAddress(t *testing.T) { "https://chromium.googlesource.com/chromiumos/third_party/kernel": true, "https://fuchsia.googlesource.com": true, "git@my-github.com:my/fd.git": true, + "file:///repo/linux.git": true, "git@my-github.com:/fd.git": false, "gitgit@my-github:/fd.git": false, "git@my-github/fd.git": false, -- cgit mrf-deployment