aboutsummaryrefslogtreecommitdiffstats
path: root/clients/common.go
diff options
context:
space:
mode:
Diffstat (limited to 'clients/common.go')
-rw-r--r--clients/common.go25
1 files changed, 23 insertions, 2 deletions
diff --git a/clients/common.go b/clients/common.go
index fcbacf5..b2e906d 100644
--- a/clients/common.go
+++ b/clients/common.go
@@ -1,10 +1,31 @@
package clients
import (
+ "fmt"
+ "net/url"
+
"gopkg.in/src-d/go-git.v2/clients/common"
+ "gopkg.in/src-d/go-git.v2/clients/file"
"gopkg.in/src-d/go-git.v2/clients/http"
+ "gopkg.in/src-d/go-git.v2/clients/ssh"
)
-func NewGitUploadPackService() common.GitUploadPackService {
- return http.NewGitUploadPackService()
+// NewGitUploadPackService returns the appropiate upload pack service
+// among of the set of supported protocols: HTTP, SSH or file.
+// TODO: should this get a scheme as an argument instead of an URL?
+func NewGitUploadPackService(repoURL string) (common.GitUploadPackService, error) {
+ u, err := url.Parse(repoURL)
+ if err != nil {
+ return nil, fmt.Errorf("invalid url %q", repoURL)
+ }
+ switch u.Scheme {
+ case "http", "https":
+ return http.NewGitUploadPackService(), nil
+ case "ssh":
+ return ssh.NewGitUploadPackService(), nil
+ case "file":
+ return file.NewGitUploadPackService(), nil
+ default:
+ return nil, fmt.Errorf("unsupported scheme %q", u.Scheme)
+ }
}