forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
clone.go
54 lines (43 loc) · 1.36 KB
/
clone.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package git
import (
"path/filepath"
"github.com/golang/glog"
"github.com/openshift/source-to-image/pkg/api"
"github.com/openshift/source-to-image/pkg/util"
)
type Clone struct {
Git
util.FileSystem
}
// Download downloads the application source code from the GIT repository
// and checkout the Ref specified in the request.
func (c *Clone) Download(request *api.Request) error {
targetSourceDir := filepath.Join(request.WorkingDir, "upload", "src")
if c.ValidCloneSpec(request.Source) {
if len(request.ContextDir) > 0 {
targetSourceDir = filepath.Join(request.WorkingDir, "upload", "tmp")
}
glog.V(2).Infof("Cloning into %s", targetSourceDir)
if err := c.Clone(request.Source, targetSourceDir); err != nil {
glog.Errorf("Git clone failed: %+v", err)
return err
}
if request.Ref != "" {
glog.V(1).Infof("Checking out ref %s", request.Ref)
if err := c.Checkout(targetSourceDir, request.Ref); err != nil {
return err
}
}
if len(request.ContextDir) > 0 {
originalTargetDir := filepath.Join(request.WorkingDir, "upload", "src")
c.RemoveDirectory(originalTargetDir)
err := c.Copy(filepath.Join(targetSourceDir, request.ContextDir), originalTargetDir)
if err != nil {
return err
}
c.RemoveDirectory(targetSourceDir)
}
return nil
}
return c.Copy(filepath.Join(request.Source, request.ContextDir), targetSourceDir)
}