Compare commits

..

4 Commits

2 changed files with 18 additions and 3 deletions

View File

@ -3,6 +3,8 @@ package project
import ( import (
"log" "log"
"net/url" "net/url"
"os"
"strings"
"github.com/pkg/errors" "github.com/pkg/errors"
"gopkg.in/src-d/go-billy.v4" "gopkg.in/src-d/go-billy.v4"
@ -15,6 +17,8 @@ import (
) )
const GitScheme = "git" const GitScheme = "git"
const HTTPScheme = "http"
const HTTPSScheme = "https"
type GitFetcher struct{} type GitFetcher struct{}
@ -53,6 +57,7 @@ func (f *GitFetcher) Fetch(url *url.URL) (billy.Filesystem, error) {
URL: url.String(), URL: url.String(),
Auth: auth, Auth: auth,
ReferenceName: branchName, ReferenceName: branchName,
Progress: os.Stdout,
}) })
if err != nil { if err != nil {
if err == transport.ErrRepositoryNotFound { if err == transport.ErrRepositoryNotFound {
@ -85,6 +90,10 @@ func (f *GitFetcher) Match(url *url.URL) bool {
return true return true
} }
if (url.Scheme == HTTPSScheme || url.Scheme == HTTPScheme) && strings.HasSuffix(url.Path, ".git") {
return true
}
isFilesystemPath := isFilesystemPath(url.Path) isFilesystemPath := isFilesystemPath(url.Path)
if url.Scheme == "" && !isFilesystemPath { if url.Scheme == "" && !isFilesystemPath {
return true return true

View File

@ -4,6 +4,8 @@ import (
"net/url" "net/url"
"strings" "strings"
"gopkg.in/src-d/go-billy.v4/osfs"
"gopkg.in/src-d/go-billy.v4" "gopkg.in/src-d/go-billy.v4"
) )
@ -13,7 +15,7 @@ const FileScheme = "file"
type LocalFetcher struct{} type LocalFetcher struct{}
func (f *LocalFetcher) Fetch(url *url.URL) (billy.Filesystem, error) { func (f *LocalFetcher) Fetch(url *url.URL) (billy.Filesystem, error) {
return nil, nil return osfs.New(url.Path), nil
} }
func (f *LocalFetcher) Match(url *url.URL) bool { func (f *LocalFetcher) Match(url *url.URL) bool {
@ -21,7 +23,11 @@ func (f *LocalFetcher) Match(url *url.URL) bool {
return true return true
} }
return isFilesystemPath(url.Path) if url.Scheme == "" && isFilesystemPath(url.Path) {
return true
}
return false
} }
func NewLocalFetcher() *LocalFetcher { func NewLocalFetcher() *LocalFetcher {
@ -29,5 +35,5 @@ func NewLocalFetcher() *LocalFetcher {
} }
func isFilesystemPath(path string) bool { func isFilesystemPath(path string) bool {
return strings.HasPrefix(path, "./") || strings.HasPrefix(path, "/") return strings.HasPrefix(path, ".") || strings.HasPrefix(path, "/")
} }