• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Golang vcs.NewRepo函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/Masterminds/vcs.NewRepo函数的典型用法代码示例。如果您正苦于以下问题:Golang NewRepo函数的具体用法?Golang NewRepo怎么用?Golang NewRepo使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了NewRepo函数的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: GetRepo

// GetRepo retrieves a Masterminds/vcs repo object configured for the root
// of the package being retrieved.
func (d *Dependency) GetRepo(dest string) (vcs.Repo, error) {

	// The remote location is either the configured repo or the package
	// name as an https url.
	var remote string
	if len(d.Repository) > 0 {
		remote = d.Repository
	} else {
		remote = "https://" + d.Name
	}

	// If the VCS type has a value we try that first.
	if len(d.VcsType) > 0 && d.VcsType != "None" {
		switch vcs.Type(d.VcsType) {
		case vcs.Git:
			return vcs.NewGitRepo(remote, dest)
		case vcs.Svn:
			return vcs.NewSvnRepo(remote, dest)
		case vcs.Hg:
			return vcs.NewHgRepo(remote, dest)
		case vcs.Bzr:
			return vcs.NewBzrRepo(remote, dest)
		default:
			return nil, fmt.Errorf("Unknown VCS type %s set for %s", d.VcsType, d.Name)
		}
	}

	// When no type set we try to autodetect.
	return vcs.NewRepo(remote, dest)
}
开发者ID:h2non,项目名称:glide,代码行数:32,代码来源:yaml.go


示例2: GetAll

// GetAll gets zero or more repos.
//
// Params:
//	- packages ([]string): Package names to get.
// 	- verbose (bool): default false
//
// Returns:
// 	- []*Dependency: A list of constructed dependencies.
func GetAll(c cookoo.Context, p *cookoo.Params) (interface{}, cookoo.Interrupt) {
	names := p.Get("packages", []string{}).([]string)
	cfg := p.Get("conf", nil).(*Config)

	Info("Preparing to install %d package.", len(names))

	deps := []*Dependency{}
	for _, name := range names {
		cwd, err := VendorPath(c)
		if err != nil {
			return nil, err
		}

		root := getRepoRootFromPackage(name)
		if len(root) == 0 {
			return nil, fmt.Errorf("Package name is required for %q.", name)
		}

		if cfg.HasDependency(root) {
			Warn("Package %q is already in glide.yaml. Skipping", root)
			continue
		}

		dest := path.Join(cwd, root)
		repoURL := "https://" + root
		repo, err := v.NewRepo(repoURL, dest)
		if err != nil {
			Error("Could not construct repo for %q: %s", name, err)
			return false, err
		}

		dep := &Dependency{
			Name: root,
		}
		subpkg := strings.TrimPrefix(name, root)
		if len(subpkg) > 0 && subpkg != "/" {
			dep.Subpackages = []string{subpkg}
		}

		if err := repo.Get(); err != nil {
			return dep, err
		}

		cfg.Imports = append(cfg.Imports, dep)

		deps = append(deps, dep)

	}
	return deps, nil
}
开发者ID:frozzare,项目名称:glide,代码行数:58,代码来源:get_imports.go


示例3: Get

// Get fetches a single package and puts it in vendor/.
//
// Params:
//	- package (string): Name of the package to get.
// 	- verbose (bool): default false
//
// Returns:
// 	- *Dependency: A dependency describing this package.
func Get(c cookoo.Context, p *cookoo.Params) (interface{}, cookoo.Interrupt) {
	name := p.Get("package", "").(string)
	cfg := p.Get("conf", nil).(*Config)

	cwd, err := VendorPath(c)
	if err != nil {
		return nil, err
	}

	root := getRepoRootFromPackage(name)
	if len(root) == 0 {
		return nil, fmt.Errorf("Package name is required.")
	}

	if cfg.HasDependency(root) {
		return nil, fmt.Errorf("Package '%s' is already in glide.yaml", root)
	}

	dest := path.Join(cwd, root)
	repoUrl := "https://" + root
	repo, err := v.NewRepo(repoUrl, dest)
	if err != nil {
		return false, err
	}

	dep := &Dependency{
		Name:    root,
		VcsType: string(repo.Vcs()),

		// Should this assume a remote https root at all times?
		Repository: repoUrl,
	}
	subpkg := strings.TrimPrefix(name, root)
	if len(subpkg) > 0 && subpkg != "/" {
		dep.Subpackages = []string{subpkg}
	}

	if err := repo.Get(); err != nil {
		return dep, err
	}

	cfg.Imports = append(cfg.Imports, dep)

	return dep, nil
}
开发者ID:jackspirou,项目名称:glide,代码行数:53,代码来源:get_imports.go


示例4: NewPackage

func NewPackage(importPath string, goPath string) (*GoPackage, error) {
	fullPath, err := goPackageDir(importPath, goPath)
	if err != nil {
		return nil, err
	}

	repoRoot, err := repoRoot(fullPath)
	if err != nil {
		return nil, fmt.Errorf("Cannot find repo root for %v: %v",
			fullPath, err)
	}

	pkgRoot := strings.TrimPrefix(repoRoot, goPath+"/src/")

	if strings.Contains(pkgRoot, "/vendor/") {
		return nil, nil
	}

	repo, err := vcs.NewRepo("", repoRoot)
	if err != nil {
		return nil, fmt.Errorf("Error while creating repo for %v: %v",
			repoRoot, err)
	}
	revision, err := repo.Version()
	if err != nil {
		return nil, err
	}
	updateDate, err := repo.Date()
	if err != nil {
		return nil, err
	}

	return &GoPackage{
		Name:       nixName(pkgRoot),
		ImportPath: pkgRoot,
		VcsRepo:    repo.Remote(),
		VcsCommand: string(repo.Vcs()),
		Revision:   revision,
		Hash:       calculateHash("file://"+repo.LocalPath(), string(repo.Vcs())),
		UpdateDate: updateDate,
	}, nil
}
开发者ID:kamilchm,项目名称:go2nix,代码行数:42,代码来源:save.go


示例5: Clone

// Clone will clone the repo to a specified location and then checkout the repo at the particular revision.
func (m Manager) Clone(url string, revision string, dir string) error {
	log.Printf("Initializing repo %s into %s\n", url, dir)
	repo, err := vcs.NewRepo(url, dir)
	if err != nil {
		return fmt.Errorf(errorContainer, repoInitFailed, url, revision, dir, err.Error())
	}
	log.Printf("Cloning %s into %s\n", url, dir)
	err = repo.Get()
	if err != nil {
		return fmt.Errorf(errorContainer, repoCloneFailed, url, revision, dir, err.Error())
	}
	if revision != "" {
		log.Printf("Checking out revision %s for repo %s\n", revision, url)
		err = repo.UpdateVersion(revision)
		if err != nil {
			return fmt.Errorf(errorContainer, repoCheckoutFailed, url, revision, dir, err.Error())
		}
	} else {
		log.Printf("Assuming default revision for repo %s\n", url)
	}
	return nil
}
开发者ID:geramirez,项目名称:compliance-masonry,代码行数:23,代码来源:manager.go


示例6: wizardFindVersions

func wizardFindVersions(d *cfg.Dependency) {
	l, err := cache.Location()
	if err != nil {
		msg.Debug("Problem detecting cache location: %s", err)
		return
	}
	var remote string
	if d.Repository != "" {
		remote = d.Repository
	} else {
		remote = "https://" + d.Name
	}

	key, err := cache.Key(remote)
	if err != nil {
		msg.Debug("Problem generating cache key for %s: %s", remote, err)
		return
	}

	local := filepath.Join(l, "src", key)
	repo, err := vcs.NewRepo(remote, local)
	if err != nil {
		msg.Debug("Problem getting repo instance: %s", err)
		return
	}

	var useLocal bool
	if _, err = os.Stat(local); err == nil {
		useLocal = true
	}

	// Git endpoints allow for querying without fetching the codebase locally.
	// We try that first to avoid fetching right away. Is this premature
	// optimization?
	cc := true
	if !useLocal && repo.Vcs() == vcs.Git {
		out, err2 := exec.Command("git", "ls-remote", remote).CombinedOutput()
		if err2 == nil {
			cache.MemTouch(remote)
			cc = false
			lines := strings.Split(string(out), "\n")
			for _, i := range lines {
				ti := strings.TrimSpace(i)
				if found := createGitParseVersion.FindString(ti); found != "" {
					tg := strings.TrimPrefix(strings.TrimSuffix(found, "^{}"), "tags/")
					cache.MemPut(remote, tg)
					if d.Reference != "" && strings.HasPrefix(ti, d.Reference) {
						cache.MemSetCurrent(remote, tg)
					}
				}
			}
		}
	}

	if cc {
		cache.Lock(key)
		cache.MemTouch(remote)
		if _, err = os.Stat(local); os.IsNotExist(err) {
			repo.Get()
			branch := findCurrentBranch(repo)
			c := cache.RepoInfo{DefaultBranch: branch}
			err = cache.SaveRepoData(key, c)
			if err != nil {
				msg.Debug("Error saving cache repo details: %s", err)
			}
		} else {
			repo.Update()
		}
		tgs, err := repo.Tags()
		if err != nil {
			msg.Debug("Problem getting tags: %s", err)
		} else {
			for _, v := range tgs {
				cache.MemPut(remote, v)
			}
		}
		if d.Reference != "" && repo.IsReference(d.Reference) {
			tgs, err = repo.TagsFromCommit(d.Reference)
			if err != nil {
				msg.Debug("Problem getting tags for commit: %s", err)
			} else {
				if len(tgs) > 0 {
					for _, v := range tgs {
						if !(repo.Vcs() == vcs.Hg && v == "tip") {
							cache.MemSetCurrent(remote, v)
						}
					}
				}
			}
		}
		cache.Unlock(key)
	}
}
开发者ID:Zuozuohao,项目名称:glide,代码行数:93,代码来源:config_wizard.go



注:本文中的github.com/Masterminds/vcs.NewRepo函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang vcs.GitRepo类代码示例发布时间:2022-05-23
下一篇:
Golang vcs.NewGitRepo函数代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap