大厅,如何使用所有远程分支提取 git 回购协议

concourse, how to pull a git repo with all remote branches

我想创建一个可以审计 git 存储库分支的 concourse 作业。但是,git 资源和我尝试过的许多其他类似资源只能将一个分支拉入回购协议。我需要能够让大厅下载包含所有远程分支的回购协议。我该怎么做?

我已经尝试了以下不下载所有远程分支的选项:

https://github.com/vito/git-branches-resource

https://github.com/cloudfoundry-community/git-multibranch-resource

我也无法在资源下载后用git命令拉下多余的分支:

root@e17c8b62-a8ac-4572-5e8f-d880c815ddff:/tmp/build/6bbb901a/my-repo# git fetch
root@e17c8b62-a8ac-4572-5e8f-d880c815ddff:/tmp/build/6bbb901a/my-repo# git branch -r
  origin/HEAD -> origin/master
  origin/master
root@e17c8b62-a8ac-4572-5e8f-d880c815ddff:/tmp/build/6bbb901a/my-repo# git fetch --all
Fetching origin
root@e17c8b62-a8ac-4572-5e8f-d880c815ddff:/tmp/build/6bbb901a/my-repo# git branch -r
  origin/HEAD -> origin/master
  origin/master

仅供参考,这是我正在寻找的信息:

$ git branch -r
  origin/HEAD -> origin/master
  origin/asdf
  origin/master
  origin/test

我不能 运行 额外的拉命令,因为我想 运行 这针对私人回购并且不想将我的 ssh 密钥插入大厅。

我注意到拉回的 .git/config 被设置为单个分支,这意味着它是 configured for remote tracking:

[origin]
fetch = +refs/heads/master:refs/remotes/origin/master

用 * 替换该行中的 master 解决了问题,但我想要一个更少手动的解决方案:

fetch = +refs/heads/*:refs/remotes/origin/*

一个选项是在作业中使用 sed 命令修复它:

cat .git/config | sed -e  's/master/*/g' > .git/config
git fetch --all

git branch -r
  origin/HEAD -> origin/master
  origin/asdf
  origin/master
  origin/test

不过我想要一些不那么凌乱的东西。

只需执行 git fetch,它会自动执行。

在使用 git fetch 之前,您需要执行几个步骤:

  • 将有效的git私钥传递给容器并将其放入~/.ssh/id_rsa

  • 将 github 主机指纹添加到您的 ~/.ssh/config & chmod 0600

  • 设置 github 全局配置 git config user.email "${GIT_USER_EMAIL}" git config user.name "${GIT_USER_NAME}"

现在您可以在 docker 容器中使用 git 做任何您想做的事情。

只是 copy/paste 下面的代码在 task.yml 文件中

---
platform: linux
image_resource:
  type: docker-image
  source: {repository: alpine/git}
run:
  path: sh
  args:
  - -exc
  - |
    git clone https://github.com/octocat/Hello-World.git
    cd Hello-World
    git branch -r

执行方式:

fly -t local execute -c task.yml

如果将存储库作为输入传递,则可以跳过 "git clone" 步骤。

您可以将其保留在任务文件中,或者在您有预期行为时将此配置移至您的管道。

这是添加到所有远程分支的正确获取命令:

git fetch origin '+refs/heads/*:refs/remotes/origin/*'