How to add submodule correctly with non-standard refspec?

1.3k Views Asked by At

We are using Gerrit for code review. Gerrit stores reviewed code in non-standard reference path - refs/changes. So, reference to commit looks like refs/changes/95/295/2 . I want to add project from Gerrit to my superproject as a submodule.

I can do it in two steps:

  • add my project as a submodule to commit-hash currently pointed by master
  • perform git fetch origin refs/changes/95/295/2 && git checkout FETCH_HEAD and commit the change.

But when I try to checkout my superproject and do git update --init git reports failure. Git can't find hash in submodule, because git didn't see references in refs/changes by default, and don't download objects from them.

Ok, I can fix it with executing git config --add remote.origin.fetch '+refs/changes/*:refs/remotes/origin/changes/*' in my gerrit repo, then retry submodule update, and that will be ok.

Question is, can I perform "add" and "init/update" submodule in one step as in usuial workflow? Basically, I need feature to set refspec before "clone"/"pull"/"submodule add"/"sumbodule update" execution start.

1

There are 1 best solutions below

3
On

You don't want to push up a change with the submodule pointing to a commit at refs/changes. Gerrit stores code there during review, but after the review is complete and the change has been submitted it can be accessed from the standard refs/heads/. Your submodules should point to the reviewed & submitted code at refs/heads/BRANCH_NAME.