Go Git - 递归子模块

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 pkg 并尝试使用此处所示的选项进行克隆,

cloneOpts := &git.CloneOptions{
      URL:               url,
      RecurseSubmodules: git.DefaultSubmoduleRecursionDepth,
}

不递归拉取子模块。我只看到空目录。我错过了什么吗?

即使在你的评论之后,我也不知道你目前是如何使用的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,
        // 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")
}

正如您在 运行 之后看到的那样,example-repo/js 包含克隆的子模块。