github.com/jogo/docker@v1.7.0-rc1/pkg/urlutil/git.go (about)

     1  package urlutil
     2  
     3  import (
     4  	"regexp"
     5  	"strings"
     6  )
     7  
     8  var (
     9  	validPrefixes = []string{
    10  		"git://",
    11  		"github.com/",
    12  		"git@",
    13  	}
    14  
    15  	urlPathWithFragmentSuffix = regexp.MustCompile(".git(?:#.+)?$")
    16  )
    17  
    18  // IsGitURL returns true if the provided str is a git repository URL.
    19  func IsGitURL(str string) bool {
    20  	if IsURL(str) && urlPathWithFragmentSuffix.MatchString(str) {
    21  		return true
    22  	}
    23  	for _, prefix := range validPrefixes {
    24  		if strings.HasPrefix(str, prefix) {
    25  			return true
    26  		}
    27  	}
    28  	return false
    29  }
    30  
    31  // IsGitTransport returns true if the provided str is a git transport by inspecting
    32  // the prefix of the string for known protocols used in git.
    33  func IsGitTransport(str string) bool {
    34  	return IsURL(str) || strings.HasPrefix(str, "git://") || strings.HasPrefix(str, "git@")
    35  }