mirror of
				https://github.com/moby/moby.git
				synced 2022-11-09 12:21:53 -05:00 
			
		
		
		
	Use git url fragment to specify reference and dir context.
Signed-off-by: David Calavera <david.calavera@gmail.com>
This commit is contained in:
		
							parent
							
								
									790c63a5ef
								
							
						
					
					
						commit
						49fd83a25e
					
				
					 6 changed files with 247 additions and 13 deletions
				
			
		| 
						 | 
				
			
			@ -1,6 +1,9 @@
 | 
			
		|||
package urlutil
 | 
			
		||||
 | 
			
		||||
import "strings"
 | 
			
		||||
import (
 | 
			
		||||
	"regexp"
 | 
			
		||||
	"strings"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
var (
 | 
			
		||||
	validPrefixes = []string{
 | 
			
		||||
| 
						 | 
				
			
			@ -8,11 +11,13 @@ var (
 | 
			
		|||
		"github.com/",
 | 
			
		||||
		"git@",
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	urlPathWithFragmentSuffix = regexp.MustCompile(".git(?:#.+)?$")
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
// IsGitURL returns true if the provided str is a git repository URL.
 | 
			
		||||
func IsGitURL(str string) bool {
 | 
			
		||||
	if IsURL(str) && strings.HasSuffix(str, ".git") {
 | 
			
		||||
	if IsURL(str) && urlPathWithFragmentSuffix.MatchString(str) {
 | 
			
		||||
		return true
 | 
			
		||||
	}
 | 
			
		||||
	for _, prefix := range validPrefixes {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -9,10 +9,15 @@ var (
 | 
			
		|||
		"git@bitbucket.org:atlassianlabs/atlassian-docker.git",
 | 
			
		||||
		"https://github.com/docker/docker.git",
 | 
			
		||||
		"http://github.com/docker/docker.git",
 | 
			
		||||
		"http://github.com/docker/docker.git#branch",
 | 
			
		||||
		"http://github.com/docker/docker.git#:dir",
 | 
			
		||||
	}
 | 
			
		||||
	incompleteGitUrls = []string{
 | 
			
		||||
		"github.com/docker/docker",
 | 
			
		||||
	}
 | 
			
		||||
	invalidGitUrls = []string{
 | 
			
		||||
		"http://github.com/docker/docker.git:#branch",
 | 
			
		||||
	}
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
func TestValidGitTransport(t *testing.T) {
 | 
			
		||||
| 
						 | 
				
			
			@ -35,9 +40,16 @@ func TestIsGIT(t *testing.T) {
 | 
			
		|||
			t.Fatalf("%q should be detected as valid Git url", url)
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	for _, url := range incompleteGitUrls {
 | 
			
		||||
		if IsGitURL(url) == false {
 | 
			
		||||
			t.Fatalf("%q should be detected as valid Git url", url)
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	for _, url := range invalidGitUrls {
 | 
			
		||||
		if IsGitURL(url) == true {
 | 
			
		||||
			t.Fatalf("%q should not be detected as valid Git prefix", url)
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue