-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1886 from tonistiigi/git-proto-fix
fix building from git url without a protocol
- Loading branch information
Showing
5 changed files
with
43 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package sshutil | ||
|
||
import ( | ||
"regexp" | ||
) | ||
|
||
var gitSSHRegex = regexp.MustCompile("^[a-zA-Z0-9-_]+@[a-zA-Z0-9-.]+:.*$") | ||
|
||
func IsSSHTransport(s string) bool { | ||
return gitSSHRegex.MatchString(s) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package sshutil | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestIsSSHTransport(t *testing.T) { | ||
require.False(t, IsSSHTransport("http://github.com/moby/buildkit")) | ||
require.False(t, IsSSHTransport("github.com/moby/buildkit")) | ||
require.False(t, IsSSHTransport("github.com:moby/buildkit.git")) | ||
require.False(t, IsSSHTransport("helloworld.net")) | ||
require.False(t, IsSSHTransport("[email protected]")) | ||
require.False(t, IsSSHTransport("[email protected]/foo/bar.git")) | ||
require.False(t, IsSSHTransport("bad:[email protected]:foo/bar.git")) | ||
require.False(t, IsSSHTransport("")) | ||
require.True(t, IsSSHTransport("[email protected]:moby/buildkit.git")) | ||
require.True(t, IsSSHTransport("[email protected]:/srv/repos/weird/project.git")) | ||
require.True(t, IsSSHTransport("[email protected]:path/to/repo.git/")) | ||
require.True(t, IsSSHTransport("[email protected]:/to/really:odd:repo.git/")) | ||
require.True(t, IsSSHTransport("[email protected]:/~/catnip.git/")) | ||
} |