问题标签 [go-git]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
0 回答
30 浏览

go - Go-Git 自定义推送选项

我想从 go 程序推送到 gitlab。我正在使用go-git v5。标准推送工作正常:

现在我想添加一个自定义 gitlab 推送选项“ci.skip”。

git 命令将是git push -o ci.skip. 我尝试添加这样的选项:

但编译器告诉我

p.Options undefined (type *git.PushOptions has no field or method Options)

我真的不明白,因为PushOptions结构显然具有此属性。我对 Go 很陌生,所以我可能在这里错过了一些概念。

0 投票
1 回答
27 浏览

go - golang git - 如果 repo 已经被克隆而不是再次克隆它,有没有办法从远程分支中提取最新的

我有一个 repo,需要每天为一些数据克隆。golang 中是否有一种方法可以使用 go-git 库仅克隆一次 repo 并使用 git pull 更新 repo?

0 投票
1 回答
21 浏览

git - go-git "git 子模块添加 "

TLDR

我一直在搜索包Docs和官方示例,但不知道如何描述使用 go-git 添加子模块。我正在尝试git submodule add <url> <submod_name>,并将其配置为稀疏结帐

目标

我想使用 golang 的 go-git 包转换以下列表。我的总体目标是有一个稀疏签出的子模块,它将来自 Repo-A,然后整个 repo 将用于 Repo-B。我正在尝试从 Repo-A 获取内容,进行一些编辑并重新组织,然后将结果推送到 Repo-B。我在下面包含的所有内容都是第一步,特别是关于如何从头开始配置这个 repo+submod。

✅✅✅✅⬜ git init
_ git remote add -f <remote_name> <repo_url>
_ git clone --depth=1 --no-checkout <submod_repo_url> <submod_name>
_git submodule add <submod_repo_url> <submod_name>

  • 不知道怎么称呼它,我认为可以直接编辑 .git 目录,但这似乎很混乱。任何解释或建议将不胜感激。

git submodule absorbgitdirs

  • 不确定这是否需要,我找不到很好的描述它的作用,但它似乎不会导致问题?

git -C pinkbrain config core.sparseCheckout true(注意:仅适用于子模块)

  • 不知道如何使它工作,因为它是一个 .git 配置,但仅适用于子模块。也许只是创建一个新的 git.PlainOpen() 对象并以这种方式访问​​它的工作树?

echo "cir-1" >>.git/modules/<submod_name>/info/sparse-checkout
echo "cir-2" >>.git/modules/<submod_name>/info/sparse-checkout
git submodule update --force --checkout <submod_name>

  • 不确定这是否需要两个单独的电话?Worktree.Pull()& Worktree.Pull(),请参见下面的代码。

git pull <remote_name> main
git add .
git commit -S -m "commit example message"

我的问题

  1. 如何使用 go-git 添加子模块?
  2. 我需要单独的sw.Checkout(&git.CheckoutOptions位吗?如果是这样,我应该按什么顺序执行它们?
  3. 如何在主仓库或子模块中配置稀疏结帐?
  4. 有什么想法git submodule absorbgitdirs吗?任何有关它的信息将不胜感激

到目前为止我所拥有的(浓缩版)

注意:我有更多,但它与我的问题无关
这一位仅用于子模块更新,因为go-git文档不允许--checkout作为git.PullOptions()