From ea850377cdbdd0381fc32359316d84968de57049 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Tue, 5 Nov 2019 13:58:58 -0800 Subject: [PATCH] builder/remotecontext: allow ssh:// urls for remote context Signed-off-by: Sebastiaan van Stijn --- .../image/build/internal/git/gitutils.go | 2 +- .../image/build/internal/git/gitutils_test.go | 26 +++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/cli/command/image/build/internal/git/gitutils.go b/cli/command/image/build/internal/git/gitutils.go index 8c39d33c66..ffd5123798 100644 --- a/cli/command/image/build/internal/git/gitutils.go +++ b/cli/command/image/build/internal/git/gitutils.go @@ -209,7 +209,7 @@ func isGitTransport(str string) bool { } switch getScheme(str) { - case "git", "http", "https": + case "git", "http", "https", "ssh": return true } diff --git a/cli/command/image/build/internal/git/gitutils_test.go b/cli/command/image/build/internal/git/gitutils_test.go index aa9e052474..fbbe030764 100644 --- a/cli/command/image/build/internal/git/gitutils_test.go +++ b/cli/command/image/build/internal/git/gitutils_test.go @@ -83,6 +83,32 @@ func TestParseRemoteURL(t *testing.T) { subdir: "mydir/mysubdir/", }, }, + { + doc: "ssh, no url-fragment", + url: "ssh://github.com/user/repo.git", + expected: gitRepo{ + remote: "ssh://github.com/user/repo.git", + ref: "master", + }, + }, + { + doc: "ssh, with url-fragment", + url: "ssh://github.com/user/repo.git#mybranch:mydir/mysubdir/", + expected: gitRepo{ + remote: "ssh://github.com/user/repo.git", + ref: "mybranch", + subdir: "mydir/mysubdir/", + }, + }, + { + doc: "ssh, with url-fragment and user", + url: "ssh://foo%40barcorp.com@github.com/user/repo.git#mybranch:mydir/mysubdir/", + expected: gitRepo{ + remote: "ssh://foo%40barcorp.com@github.com/user/repo.git", + ref: "mybranch", + subdir: "mydir/mysubdir/", + }, + }, } for _, tc := range tests {