Getting local gerrit and repository working (including branches) based on a github project

廉价感情. 提交于 2019-12-18 13:18:24

问题


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?


回答1:


When you perform a git push, it only pushes the active branch (HEAD). If you wish to push all branches and tags, do something like git push origin refs/heads/* --tags

It isn't technically required to have a local copy of the repository before pushing to Gerrit, but it is probably the easiest method.




回答2:


I believe I've found the answer for myself. It boils down to how you create the repository (and is my formal introduction to bare repos).

In short, you can clone a repo the default way:

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

Which yields a local clone with working directory myrepo, within which is the myrepo/.git directory tree.

Or you can clone it bare. There are a couple of ways to do this, but the --mirror option appears to yields the most complete replica:

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

This produces the myrepo.git directory (as one might see in gerrit or in gitolite) which has the same structure as the myrepo/.git directory above, but without the working directory bits.

Note: I'll add that I'm not sure now whether a mirror is preferable to a bare clone with remote refs for the branches... I've got another thread going that inquires about this. For completeness, then, here's a way to create a bare clone with remote refs (the key being no working directory):

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

I tested the mirror idea as a one-off, cloning a repo straight into the local gerrit installation folder where All-Projects.git also lives, restarted gerrit and it sees the repo as well as all its branches. However, it's not the ideal way for gerrit. You should instead push from a local clone (preferably a bare one).

So in gerrit, create a new empty project via the web admin interface (I didn't put an initial empty commit into it - not sure if that would cause problems), then from within a local mirror of the repo you're trying to replicate, push it to the new, empty gerrit repo along with the branches and tags:

git push <gerrit_repo> refs/heads/* refs/tags/*


来源:https://stackoverflow.com/questions/12269963/getting-local-gerrit-and-repository-working-including-branches-based-on-a-gith

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!