登录
首页 >  Golang >  Go问答

使用Git递归子模块项目

来源:stackoverflow

时间:2024-02-15 10:54:23 396浏览 收藏

亲爱的编程学习爱好者,如果你点开了这篇文章,说明你对《使用Git递归子模块项目》很感兴趣。本篇文章就来给大家详细解析一下,主要介绍一下,希望所有认真读完的童鞋们,都有实质性的提高。

问题内容

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

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

文中关于的知识介绍,希望对你的学习有所帮助!若是受益匪浅,那就动动鼠标收藏这篇《使用Git递归子模块项目》文章吧,也可关注golang学习网公众号了解相关技术文章。

声明:本文转载于:stackoverflow 如有侵犯,请联系study_golang@163.com删除
相关阅读
更多>
最新阅读
更多>
课程推荐
更多>