本文整理匯總了Golang中github.com/openshift/origin/pkg/generate/git.Repository.Clone方法的典型用法代碼示例。如果您正苦於以下問題:Golang Repository.Clone方法的具體用法?Golang Repository.Clone怎麽用?Golang Repository.Clone使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/openshift/origin/pkg/generate/git.Repository
的用法示例。
在下文中一共展示了Repository.Clone方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: CloneAndCheckoutSources
// CloneAndCheckoutSources clones the remote repository using either regular
// git clone operation or shallow git clone, based on the "ref" provided (you
// cannot shallow clone using the 'ref').
// This function will return the full path to the buildable sources, including
// the context directory if specified.
func CloneAndCheckoutSources(repo git.Repository, remote, ref, localDir, contextDir string) (string, error) {
if len(ref) == 0 {
glog.V(5).Infof("No source ref specified, using shallow git clone")
if err := repo.CloneWithOptions(localDir, remote, git.Shallow, "--recursive"); err != nil {
return "", fmt.Errorf("shallow cloning repository %q to %q failed: %v", remote, localDir, err)
}
} else {
glog.V(5).Infof("Requested ref %q, performing full git clone and git checkout", ref)
if err := repo.Clone(localDir, remote); err != nil {
return "", fmt.Errorf("cloning repository %q to %q failed: %v", remote, localDir, err)
}
}
if len(ref) > 0 {
if err := repo.Checkout(localDir, ref); err != nil {
return "", fmt.Errorf("unable to checkout ref %q in %q repository: %v", ref, remote, err)
}
}
if len(contextDir) > 0 {
glog.V(5).Infof("Using context directory %q. The full source path is %q", contextDir, filepath.Join(localDir, contextDir))
}
return filepath.Join(localDir, contextDir), nil
}