本文整理汇总了Golang中github.com/Masterminds/vcs.Repo类的典型用法代码示例。如果您正苦于以下问题:Golang Repo类的具体用法?Golang Repo怎么用?Golang Repo使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Repo类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: isBranch
// isBranch returns true if the given string is a branch in VCS.
func isBranch(branch string, repo v.Repo) (bool, error) {
branches, err := repo.Branches()
if err != nil {
return false, err
}
for _, b := range branches {
if b == branch {
return true, nil
}
}
return false, nil
}
开发者ID:karfield,项目名称:glide,代码行数:13,代码来源:vcs.go
示例2: getAllVcsRefs
// Get all the references for a repo. This includes the tags and branches.
func getAllVcsRefs(repo vcs.Repo) ([]string, error) {
tags, err := repo.Tags()
if err != nil {
return []string{}, err
}
branches, err := repo.Branches()
if err != nil {
return []string{}, err
}
return append(branches, tags...), nil
}
开发者ID:rudle,项目名称:glide,代码行数:14,代码来源:semver.go
示例3: displayCommitInfo
func displayCommitInfo(repo vcs.Repo, dep *cfg.Dependency) {
c, err := repo.CommitInfo(dep.Reference)
ref := dep.Reference
if err == nil {
tgs, err2 := repo.TagsFromCommit(c.Commit)
if err2 == nil && len(tgs) > 0 {
if tgs[0] != dep.Reference {
ref = ref + " (" + tgs[0] + ")"
}
}
singleInfo(displayCommitInfoTemplate, dep.Name, ref, c.Author, c.Date.Format(time.RFC1123Z), commitSubjectFirstLine(c.Message))
}
}
开发者ID:treejames,项目名称:glide-1,代码行数:14,代码来源:installer.go
示例4: findCurrentBranch
func findCurrentBranch(repo vcs.Repo) string {
msg.Debug("Attempting to find current branch for %s", repo.Remote())
// Svn and Bzr don't have default branches.
if repo.Vcs() == vcs.Svn || repo.Vcs() == vcs.Bzr {
return ""
}
if repo.Vcs() == vcs.Git || repo.Vcs() == vcs.Hg {
ver, err := repo.Current()
if err != nil {
msg.Debug("Unable to find current branch for %s, error: %s", repo.Remote(), err)
return ""
}
return ver
}
return ""
}
开发者ID:Zuozuohao,项目名称:glide,代码行数:18,代码来源:config_wizard.go
示例5: findCurrentBranch
// From a local repo find out the current branch name if there is one.
func findCurrentBranch(repo v.Repo) string {
Debug("Attempting to find current branch for %s", repo.Remote())
// Svn and Bzr don't have default branches.
if repo.Vcs() == v.Svn || repo.Vcs() == v.Bzr {
return ""
}
if repo.Vcs() == v.Git {
c := exec.Command("git", "symbolic-ref", "--short", "HEAD")
c.Dir = repo.LocalPath()
c.Env = envForDir(c.Dir)
out, err := c.CombinedOutput()
if err != nil {
Debug("Unable to find current branch for %s, error: %s", repo.Remote(), err)
return ""
}
return strings.TrimSpace(string(out))
}
if repo.Vcs() == v.Hg {
c := exec.Command("hg", "branch")
c.Dir = repo.LocalPath()
c.Env = envForDir(c.Dir)
out, err := c.CombinedOutput()
if err != nil {
Debug("Unable to find current branch for %s, error: %s", repo.Remote(), err)
return ""
}
return strings.TrimSpace(string(out))
}
return ""
}
开发者ID:hyPiRion,项目名称:glide,代码行数:34,代码来源:get_imports.go
示例6: defaultBranch
// Some repos will have multiple branches in them (e.g. Git) while others
// (e.g. Svn) will not.
// TODO(mattfarina): Add API calls to github, bitbucket, etc.
func defaultBranch(repo v.Repo, home string) string {
// Svn and Bzr use different locations (paths or entire locations)
// for branches so we won't have a default branch.
if repo.Vcs() == v.Svn || repo.Vcs() == v.Bzr {
return ""
}
// Check the cache for a value.
key, kerr := cacheCreateKey(repo.Remote())
var d cacheRepoInfo
if kerr == nil {
d, err := cacheRepoData(key, home)
if err == nil {
if d.DefaultBranch != "" {
return d.DefaultBranch
}
}
}
// If we don't have it in the store try some APIs
r := repo.Remote()
u, err := url.Parse(r)
if err != nil {
return ""
}
if u.Scheme == "" {
// Where there is no scheme we try urls like [email protected]:foo/bar
r = strings.Replace(r, ":", "/", -1)
r = "ssh://" + r
u, err = url.Parse(r)
if err != nil {
return ""
}
u.Scheme = ""
}
if u.Host == "github.com" {
parts := strings.Split(u.Path, "/")
if len(parts) != 2 {
return ""
}
api := fmt.Sprintf("https://api.github.com/repos/%s/%s", parts[0], parts[1])
resp, err := http.Get(api)
if err != nil {
return ""
}
defer resp.Body.Close()
if resp.StatusCode >= 300 || resp.StatusCode < 200 {
return ""
}
body, err := ioutil.ReadAll(resp.Body)
var data interface{}
err = json.Unmarshal(body, &data)
if err != nil {
return ""
}
gh := data.(map[string]interface{})
db := gh["default_branch"].(string)
if kerr == nil {
d.DefaultBranch = db
saveCacheRepoData(key, d, home)
}
return db
}
if u.Host == "bitbucket.org" {
parts := strings.Split(u.Path, "/")
if len(parts) != 2 {
return ""
}
api := fmt.Sprintf("https://bitbucket.org/api/1.0/repositories/%s/%s/main-branch/", parts[0], parts[1])
resp, err := http.Get(api)
if err != nil {
return ""
}
defer resp.Body.Close()
if resp.StatusCode >= 300 || resp.StatusCode < 200 {
return ""
}
body, err := ioutil.ReadAll(resp.Body)
var data interface{}
err = json.Unmarshal(body, &data)
if err != nil {
return ""
}
bb := data.(map[string]interface{})
db := bb["name"].(string)
if kerr == nil {
d.DefaultBranch = db
saveCacheRepoData(key, d, home)
}
return db
}
return ""
}
开发者ID:hyPiRion,项目名称:glide,代码行数:99,代码来源:get_imports.go
注:本文中的github.com/Masterminds/vcs.Repo类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论