Import repository from git to gerrit
Asked Answered
I

4

29

I have two questions about Gerrit:

  1. How do I convert or import an already existing Git repository into Gerrit's format? There were a lot of commits without Gerrit control, I want to simply push those commits into a Gerrit project.

    I see two ways to do it:

    1. Copy existing bare Git directory to Gerrit and then add it to database. Is that a safe method?

    2. Push all commits from my local repository to gerrit repository.

  2. How to revert repository from Gerrit to original Git format? Is it required to remove Gerrit's special */for/* branches to do that?

Interference answered 9/2, 2013 at 15:36 Comment(0)
D
31

First of all: There is no special "Gerrit format". Gerrit works with regular git repositories.

  1. Create a new project in Gerrit (without an initial commit). Add the created repository as a remote to your existing repository and simply push. You can configure Gerrit to allow direct pushing into the repository (bypassing review), allowing you to import the entire repository.

    Alternatively, if you have direct access to Gerrit's repository location (e.g. via SSH or on the local filesystem), you can just push directly into the repository (whereever Gerrit created it), bypassing Gerrit entirely. You'll need to flush the Gerrit caches afterwards, however, for Gerrit to notice that the repository HEADs have updated.

  2. As said, there is no "Gerrit format". Just clone your repository from gerrit, and all is well. You don't need to worry about any special branches.

Dorian answered 9/2, 2013 at 16:8 Comment(2)
Also some point about user access rights (when pushing). You must have Create Reference, Push, Push Merge Commit and Push Annotated Tag rights for successfull push of all old commits. Also all users of commits must be registred or have aliases of emails in the gerrit.Interference
You can avoid the need to register all commit authors giving also the "Forge Committer Identity" right.Ariannearianrhod
G
8

I imported many GIT projects to gerrit, the easiest way I found was to copy the xy.git Directory of the git repository to the directory where gerrit deposits the git repos. After restart of gerrit process the new project is in the list of new projects and you can edit description and access rights.

Grane answered 25/10, 2013 at 11:7 Comment(3)
Indeed quite an easy way. Creating symlink also works. And restarting gerrit is actually not needed.Stander
I've tried this approach on gerrit 2.9. Restart is needed otherwise the new added project won't show in the project list.Scream
if the project doesn't show up, flushing the cache (as helmbert suggested) should be sufficient. (it worked for me.)Befuddle
M
6
  1. Just create the new project in Gerrit, and then push the git repository there. If you want to bypass review, push directly to master instead of refs/for/master. You'll need to add the permission to do this to yourself.

    I think the error message may be caused by you not having imported your ssh key to Gerrit yet.

  2. Just clone the repository from Gerrit. It won't include any extra branches.

Mhd answered 9/2, 2013 at 16:0 Comment(0)
D
0

Additional information...

So you can copy the git repository straight across into the gerrit data location and it will show up after a restart ( or flush of cache ( reindex )).

BUT you will be missing the important configuration from your repository, which may prevent ability to push, create branches, review etc.

If you view the repo you will see it is missing the 'refs/meta/config' branch. So in an normal system without changes this will inherit from All-Projects, but this could be any Project on your configuration.

Steps to fix configuration:

  1. List item
  2. Copy git repo
  3. Refresh cache / restart gerrit / reindex
  4. Open repo from project list view
  5. Click on branches
  6. Type in the new branch name of "refs/meta/config" at revision "HEAD"
  7. Click "edit config" from the project general view.
  8. This creates a file (project.config) in this branch for configuration. Add some default configuration, either taken from a working repo, or as follows:

e.g.

[access]
   inheritFrom = All-Projects
  1. Click Save, then CLOSE.
  2. Click Review ( to give it +2)
  3. Click Publish Edit to save this change into gerrit.

You can now use the repository with sensible inherited configuration the same as your other projects.

Dismount answered 1/5, 2019 at 19:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.