【问题标题】:Go Git - Recurse SubmodulesGo Git - 递归子模块
【发布时间】:2022-01-20 02:17:49
【问题描述】:

我有一个项目,其中包含如下所示的子模块。

[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 实现不使用 Git,所以这是一个纯粹的 go-git 问题。
  • 我无法重现这一点,PlainClone 方法正确克隆了我测试过的 repo 的子模块。
  • 是的,这需要minimal reproducible example。
  • @OliverTale-Yazdi 我的父模块只包含上面的文件.gitmodule。你还有什么事吗?
  • @torek 那么当你克隆这个example repo 时会发生什么? js 文件夹的内容是否存在?否则我需要查看代码以更好地帮助您。

标签: go go-git


【解决方案1】:

即使在您的 cmets 之后,我也不知道您目前如何使用go-git;所以请提供你的源代码。

我现在在go-git 中回答您关于“如何克隆 repo 及其子模块”的原始问题:

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 包含克隆的子模块。

【讨论】:

  • 它工作的人。对不起,这是我的错。但我非常感谢您花时间创建 repo 并展示一个工作示例。
  • @RamPrakash 不用担心,我很乐意为您提供帮助 ?
猜你喜欢
  • 2012-04-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-01-24
  • 1970-01-01
  • 1970-01-01
  • 2018-05-29
  • 1970-01-01
相关资源
最近更新 更多