@@ -5,14 +5,17 @@ import (
55"strings"
66
77"github.com/michelvocks/gaia"
8+ "github.com/satori/go.uuid"
89git"gopkg.in/src-d/go-git.v4"
910"gopkg.in/src-d/go-git.v4/plumbing/transport"
1011"gopkg.in/src-d/go-git.v4/plumbing/transport/client"
12+ "gopkg.in/src-d/go-git.v4/plumbing/transport/http"
1113"gopkg.in/src-d/go-git.v4/plumbing/transport/ssh"
1214)
1315
1416const (
15- refHead = "refs/heads"
17+ refHead = "refs/heads"
18+ tmpFolder = "tmp"
1619)
1720
1821// GitLSRemote get remote branches from a git repo
@@ -78,17 +81,38 @@ func GitLSRemote(repo *gaia.GitRepo) error {
7881// GitCloneRepo clones the given repo to a local folder.
7982// The destination will be attached to the given repo obj.
8083func GitCloneRepo (repo * gaia.GitRepo )error {
81- // Create local temp folder for checkout
82- folder := "temp/notyetdefined"
84+ // create uuid for clone folder
85+ uuid := uuid .Must (uuid .NewV4 ())
86+
87+ // Create local temp folder for clone
88+ folder := tmpFolder + string (os .PathSeparator )+ uuid .String ()
8389err := os .MkdirAll (folder ,0700 )
8490if err != nil {
8591return err
8692}
8793
94+ // Check if credentials were provided
95+ var auth transport.AuthMethod
96+ if repo .Username != "" && repo .Password != "" {
97+ // Basic auth provided
98+ auth = & http.BasicAuth {
99+ Username :repo .Username ,
100+ Password :repo .Password ,
101+ }
102+ }else if repo .PrivateKey .Key != "" {
103+ auth ,err = ssh .NewPublicKeys (repo .PrivateKey .Username , []byte (repo .PrivateKey .Key ),repo .PrivateKey .Password )
104+ if err != nil {
105+ return err
106+ }
107+ }
108+
88109// Clone repo
89110_ ,err = git .PlainClone (folder ,false ,& git.CloneOptions {
111+ Auth :auth ,
90112URL :repo .URL ,
91113RecurseSubmodules :git .DefaultSubmoduleRecursionDepth ,
114+ SingleBranch :true ,
115+ RemoteName :repo .SelectedBranch ,
92116})
93117if err != nil {
94118return err