8

Our goal is to do internal development based on a project hosted on an external repo (github) using git and gerrit. We would pull from the external repo periodically to bring in new changes and branches, and use gerrit to manage the review process (and Jenkins to build it all).

Our initial process is to clone from the external repo to a local repo via git, then create an empty project in gerrit, and finally push the local clone to gerrit.

At that point, however, we see no branches in the gerrit repo! Right now we're working around that by manually adding the branched and refids, but that seems convoluted and fragile. I'd think the external branches would come in by default, without extra contortions. They are certainly in the clone made from the github repo.

Ideally, it'd be nice to be able to clone straight from github to gerrit and have it just work... it's not clear why the extra local repo is necessary simply to transfer things, or why branches aren't appearing in the gerrit clone when the local clone is pushed to it. Suggestions?

4

2 回答 2

4

我相信我已经为自己找到了答案。它归结为您如何创建存储库(并且是我对裸存储库的正式介绍)。

简而言之,您可以使用默认方式克隆一个 repo:

git clone https://github.com/foobar/myrepo.git

这会产生一个带有工作目录myrepo的本地克隆,其中是myrepo/.git目录树。

或者你可以克隆它。有几种方法可以做到这一点,但 --mirror 选项似乎会产生最完整的副本:

git clone --mirror https://github.com/foobar/myrepo.git

这会生成myrepo.git目录(就像在 gerrit 或 gitolite 中看到的那样),它与上面的myrepo/.git目录具有相同的结构,但没有工作目录位。

注意:我要补充一点,我现在不确定镜像是否比带有分支远程参考的裸克隆更可取......我有另一个线程正在询问这个问题。为了完整起见,这里有一种使用远程引用创建裸克隆的方法(关键是没有工作目录):

git init --bare ${LOCAL_REPO}
cd ${LOCAL_REPO}
git remote add origin ${REMOTE_URL}
git fetch origin --tags
git fetch origin

我一次性测试了镜像想法,将 repo 直接克隆到All-Projects.git所在的本地 gerrit 安装文件夹中,重新启动 gerrit,它会看到 repo 及其所有分支。但是,这不是 gerrit 的理想方式。您应该改为从本地克隆(最好是裸机)推送。

因此,在 gerrit 中,通过 Web 管理界面创建一个新的空项目(我没有将初始的空提交放入其中 - 不确定这是否会导致问题),然后从您尝试的 repo 的本地镜像中创建复制,将其与分支和标签一起推送到新的空 gerrit 存储库:

git push <gerrit_repo> refs/heads/* refs/tags/*
于 2012-09-05T00:24:53.723 回答
4

当您执行 git push 时,它只会推送活动分支 (HEAD)。如果您希望推送所有分支和标签,请执行以下操作git push origin refs/heads/* --tags

在推送到 Gerrit 之前,技术上不需要拥有存储库的本地副本,但这可能是最简单的方法。

于 2012-09-04T21:21:50.960 回答