2

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.

  • Finally I implement my own abstraction level on top of git. It works, and it's ugly. I'm not happy, but maybe I can fix git behaviour providing patch to Linus. – Ivan Tolstosheyev Oct 09 '12 at 11:58

1 Answers1

0

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.

Brad
  • 5,492
  • 23
  • 34
  • 1
    No, I want to do exactly this. I need to perform build with newly pushed changes, and I can build it as submodule in superproject. – Ivan Tolstosheyev Oct 04 '12 at 07:27
  • In that case, the only option I'm aware of is to add the remote fetch spec as you indicated. This is what our build-bots do at my job to verify unmerged changes. – Brad Oct 04 '12 at 15:15
  • Yep, I can add fetch-spec, but this will be additional step after `submodule update --init` failed. I can do it, but this is ugly, IMHO. – Ivan Tolstosheyev Oct 05 '12 at 06:00