當前位置: 首頁>>代碼示例>>Golang>>正文


Golang git.Git類代碼示例

本文整理匯總了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;未經允許,請勿轉載。