本文整理汇总了Golang中github.com/openshift/source-to-image/pkg/scm/git.Git类的典型用法代码示例。如果您正苦于以下问题:Golang Git类的具体用法?Golang Git怎么用?Golang Git使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Git类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: extractGitSource
func extractGitSource(git git.Git, gitSource *api.GitBuildSource, revision *api.SourceRevision, dir string, timeout time.Duration) (bool, error) {
if gitSource == nil {
return false, nil
}
// Set the HTTP and HTTPS proxies to be used by git clone.
originalProxies := setHTTPProxy(gitSource.HTTPProxy, gitSource.HTTPSProxy)
defer resetHTTPProxy(originalProxies)
// Check source URI, trying to connect to the server only if not using a proxy.
if err := checkSourceURI(git, gitSource.URI, timeout); err != nil {
return true, err
}
glog.V(2).Infof("Cloning source from %s", gitSource.URI)
if err := git.Clone(gitSource.URI, dir, s2iapi.CloneConfig{Recursive: true, Quiet: true}); err != nil {
return true, err
}
// if we specify a commit, ref, or branch to checkout, do so
if len(gitSource.Ref) != 0 || (revision != nil && revision.Git != nil && len(revision.Git.Commit) != 0) {
commit := gitSource.Ref
if revision != nil && revision.Git != nil && revision.Git.Commit != "" {
commit = revision.Git.Commit
}
if err := git.Checkout(dir, commit); err != nil {
return true, err
}
}
return true, nil
}
开发者ID:Waxolunist,项目名称:origin,代码行数:31,代码来源:source.go
示例2: fetchSource
// fetchSource retrieves the inputs defined by the build source into the
// provided directory, or returns an error if retrieval is not possible.
func fetchSource(dir string, build *api.Build, urlTimeout time.Duration, in io.Reader, git git.Git) (*s2iapi.SourceInfo, error) {
hasGitSource := false
// expect to receive input from STDIN
if err := extractInputBinary(in, build.Spec.Source.Binary, dir); err != nil {
return nil, err
}
// may retrieve source from Git
hasGitSource, err := extractGitSource(git, build.Spec.Source.Git, build.Spec.Revision, dir, urlTimeout)
if err != nil {
return nil, err
}
var sourceInfo *s2iapi.SourceInfo
if hasGitSource {
sourceInfo = git.GetInfo(dir)
}
// a Dockerfile has been specified, create or overwrite into the destination
if dockerfileSource := build.Spec.Source.Dockerfile; dockerfileSource != nil {
baseDir := dir
// if a context dir has been defined and we cloned source, overwrite the destination
if hasGitSource && len(build.Spec.Source.ContextDir) != 0 {
baseDir = filepath.Join(baseDir, build.Spec.Source.ContextDir)
}
return sourceInfo, ioutil.WriteFile(filepath.Join(baseDir, "Dockerfile"), []byte(*dockerfileSource), 0660)
}
return sourceInfo, nil
}
开发者ID:Waxolunist,项目名称:origin,代码行数:32,代码来源:source.go
示例3: checkSourceURI
// checkSourceURI performs a check on the URI associated with the build
// to make sure that it is valid. It also optionally tests the connection
// to the source uri.
func checkSourceURI(git git.Git, rawurl string, testConnection bool, timeout time.Duration) error {
if !git.ValidCloneSpec(rawurl) {
return fmt.Errorf("Invalid git source url: %s", rawurl)
}
if strings.HasPrefix(rawurl, "[email protected]") || strings.HasPrefix(rawurl, "git://") {
return nil
}
srcURL, err := url.Parse(rawurl)
if err != nil {
return err
}
if !testConnection {
return nil
}
host := srcURL.Host
if strings.Index(host, ":") == -1 {
switch srcURL.Scheme {
case "http":
host += ":80"
case "https":
host += ":443"
}
}
dialer := net.Dialer{Timeout: timeout}
conn, err := dialer.Dial("tcp", host)
if err != nil {
return err
}
return conn.Close()
}
开发者ID:hloganathan,项目名称:origin,代码行数:33,代码来源:source.go
示例4: checkSourceURI
// checkSourceURI performs a check on the URI associated with the build
// to make sure that it is valid. It also optionally tests the connection
// to the source uri.
func checkSourceURI(git git.Git, rawurl string, timeout time.Duration) error {
if !git.ValidCloneSpec(rawurl) {
return fmt.Errorf("Invalid git source url: %s", rawurl)
}
return checkRemoteGit(rawurl, timeout)
}
开发者ID:Waxolunist,项目名称:origin,代码行数:9,代码来源:source.go
注:本文中的github.com/openshift/source-to-image/pkg/scm/git.Git类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论