英文:
Go Git - Recurse Submodules
问题
我有一个包含子模块的项目,如下所示:
[submodule "repo-a"]
path = repo-a
url = https://example.com/scm/repo-a.git
[submodule "repo-b"]
path = repo-b
url = https://example.com/scm/repo-b.git
[submodule "repo-c"]
path = repo-c
url = https://example.com/scm/repo-c.git
我正在使用 go-git 包,并尝试使用以下选项进行克隆:
cloneOpts := &git.CloneOptions{
URL: url,
RecurseSubmodules: git.DefaultSubmoduleRecursionDepth,
}
但它并没有递归地拉取子模块。我只看到空目录。我是否漏掉了什么?
英文:
I have a project which contains submodules as shown here.
[submodule "repo-a"]
path = repo-a
url = https://example.com/scm/repo-a.git
[submodule "repo-b"]
path = repo-b
url = https://example.com/scm/repo-b.git
[submodule "repo-c"]
path = repo-c
url = https://example.com/scm/repo-c.git
I am using go-git pkg and trying to clone with options as shown here,
cloneOpts := &git.CloneOptions{
URL: url,
RecurseSubmodules: git.DefaultSubmoduleRecursionDepth,
}
It does not recursively pull the submodules. I see only empty directories. Am I missing something?
答案1
得分: 2
即使在您的评论之后,我仍然不知道您目前如何使用go-git
;所以请提供您的源代码。
我现在回答您最初的问题,即在go-git
中如何克隆一个仓库及其子模块:
package main
import (
"os";
"github.com/go-git/go-git/v5";
)
func main() {
repoURL := "https://github.com/githubtraining/example-dependency";
clonePath := "example-repo";
_, err := git.PlainClone(clonePath, false, &git.CloneOptions{
URL: repoURL,
Progress: os.Stdout,
// 启用子模块克隆。
RecurseSubmodules: git.DefaultSubmoduleRecursionDepth,
})
if err != nil {
panic(err);
}
println("请查看example-repo/js,以查看克隆的子模块");
}
运行此代码后,您会发现example-repo/js
中包含了克隆的子模块。
英文:
Even after your comments, I have no idea how you are currently using go-git
; so please provide your source code.
I am now answering your original question of "how to clone a repo and its submodules" in go-git
:
package main
import (
"os"
"github.com/go-git/go-git/v5"
)
func main() {
repoURL := "https://github.com/githubtraining/example-dependency"
clonePath := "example-repo"
_, err := git.PlainClone(clonePath, false, &git.CloneOptions{
URL: repoURL,
Progress: os.Stdout,
// Enable submodule cloning.
RecurseSubmodules: git.DefaultSubmoduleRecursionDepth,
})
if err != nil {
panic(err)
}
println("Have a look at example-repo/js to see a cloned sub-module")
}
As you can see after running this, example-repo/js
contains the cloned submodule.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论