示例#1
0
// DownloaderForSource determines what SCM plugin should be used for downloading
// the sources from the repository.
func DownloaderForSource(s string) (build.Downloader, string, error) {
	details, _ := git.ParseFile(s)

	if details.FileExists && details.UseCopy {
		if !details.ProtoSpecified {
			// since not using git, any resulting URLs need to be explicit with file:// protocol specified
			s = "file://" + s
		}
		return &file.File{util.NewFileSystem()}, s, nil
	}

	if details.ProtoSpecified && !details.FileExists {
		return nil, s, fmt.Errorf("local location: %s does not exist", s)
	}

	if !details.ProtoSpecified && details.FileExists {
		// if local file system, without file://, when using git, should not need file://, but we'll be safe;
		// satisfies previous constructed test case in scm_test.go as well
		s = "file://" + s
	}

	// If the source is valid  GIT remote protocol (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)
}
示例#2
0
// DownloaderForSource determines what SCM plugin should be used for downloading
// the sources from the repository.
func DownloaderForSource(s string) (build.Downloader, string, error) {
	glog.V(4).Infof("DownloadForSource %s", s)

	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 path from parse file %s", mods.Path)
		s = mods.Path
	}

	if details.FileExists && details.UseCopy {
		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)
}
示例#3
0
文件: scm.go 项目: carriercomm/origin
// 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)

	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)
}
示例#4
0
文件: scm.go 项目: php-coder/origin
// DownloaderForSource determines what SCM plugin should be used for downloading
// the sources from the repository.
func DownloaderForSource(fs util.FileSystem, 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, err := git.ParseFile(fs, s)
	glog.V(4).Infof("return from ParseFile file exists %v proto specified %v use copy %v", details.FileExists, details.ProtoSpecified, details.UseCopy)
	if err != nil {
		if e, ok := err.(errors.Error); !forceCopy || !(ok && (e.ErrorCode == errors.EmptyGitRepositoryError)) {
			return nil, s, err
		}
	}

	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)
		s = "file://" + mods.Path
	}

	if details.FileExists && (details.UseCopy || forceCopy) {
		return &file.File{FileSystem: fs}, s, nil
	}

	// If the source is valid  Git protocol (file://, ssh://, git://, git@, etc..) use Git
	// binary to download the sources
	g := git.New(fs)
	ok, err := g.ValidCloneSpec(s)
	if err != nil {
		return nil, s, err
	}

	if ok {
		return &git.Clone{Git: g, FileSystem: fs}, s, nil
	}

	return nil, s, fmt.Errorf("no downloader defined for location: %q", s)
}