本文整理汇总了Golang中github.com/Masterminds/vcs.NewGitRepo函数的典型用法代码示例。如果您正苦于以下问题:Golang NewGitRepo函数的具体用法?Golang NewGitRepo怎么用?Golang NewGitRepo使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewGitRepo函数的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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)
}
示例2: ensureRepo
// ensureRepo ensures that the repo exists and is checked out.
func ensureRepo(repo, home string) *vcs.GitRepo {
if err := os.Chdir(home); err != nil {
log.Die("Could not change to directory %q: %s", home, err)
}
git, err := vcs.NewGitRepo(repo, home)
if err != nil {
log.Die("Could not get repository %q: %s", repo, err)
}
if !git.CheckLocal() {
log.Info("Cloning repo into %q. Please wait.", home)
if err := git.Get(); err != nil {
log.Die("Could not create repository in %q: %s", home, err)
}
}
return git
}
示例3: ensureRepo
func ensureRepo(repo, dir string) (*vcs.GitRepo, error) {
if fi, err := os.Stat(dir); err != nil {
if err := os.MkdirAll(dir, 0755); err != nil {
return nil, err
}
} else if !fi.IsDir() {
return nil, fmt.Errorf("File %s exists, but is not a directory.", dir)
}
git, err := vcs.NewGitRepo(repo, dir)
if err != nil {
return nil, err
}
git.Logger = log.New()
if !git.CheckLocal() {
if err := git.Get(); err != nil {
return git, err
}
}
return git, nil
}