forked from openshift/origin
/
scm.go
55 lines (44 loc) · 1.83 KB
/
scm.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
55
package scm
import (
"fmt"
"github.com/golang/glog"
"github.com/openshift/source-to-image/pkg/build"
"github.com/openshift/source-to-image/pkg/scm/empty"
"github.com/openshift/source-to-image/pkg/scm/file"
"github.com/openshift/source-to-image/pkg/scm/git"
"github.com/openshift/source-to-image/pkg/util"
)
// DownloaderForSource determines what SCM plugin should be used for downloading
// the sources from the repository.
func DownloaderForSource(s string, forceCopy bool) (build.Downloader, string, error) {
glog.V(4).Infof("DownloadForSource %s", s)
if len(s) == 0 {
return &empty.Noop{}, s, nil
}
details, mods := git.ParseFile(s)
glog.V(4).Infof("return from ParseFile file exists %v proto specified %v use copy %v", details.FileExists, details.ProtoSpecified, details.UseCopy)
if details.FileExists && details.BadRef {
return nil, s, fmt.Errorf("local location referenced by %s exists but the input after the # is malformed", s)
}
if details.FileExists && mods != nil {
glog.V(4).Infof("new source from parse file %s", mods.Path)
if details.ProtoSpecified {
s = mods.Path
} else {
// prepending with file:// is a precautionary step which previous incarnations of this code did; we
// preserve that behavior (it is more explicit, if not absolutely necessary; but we do it here as was done before
// vs. down in our generic git layer (which is leveraged separately in origin)
s = "file://" + mods.Path
}
}
if details.FileExists && (details.UseCopy || forceCopy) {
return &file.File{util.NewFileSystem()}, s, nil
}
// If the source is valid Git protocol (file://, ssh://, git://, git@, etc..) use Git
// binary to download the sources
g := git.New()
if g.ValidCloneSpec(s) {
return &git.Clone{g, util.NewFileSystem()}, s, nil
}
return nil, s, fmt.Errorf("no downloader defined for location: %q", s)
}