git – Cloning Android sources to a local repository server-ThrowExceptions

Exception or error:

I want to develop on top of Android using a local Android repository server. I need to add several new git repositories to the hierarchy of gits, and I need to modify existing android sources for a custom tailoring of Android.

What is the “correct” way to clone the entire Android source tree of git repositories, such that I can push/pull to/from a common local repository server, and still easily pull new changes from Android upstream?

I am specifically looking for advice on how to use the repo script for interaction with my own server, and how to set up the manifest git repository and managing branches therein.

How to solve:

On your git server

  1. repo init -u –mirror # –mirror is the key
  2. repo sync

Because you specified –mirror, all repos created will be ‘bare’ repos, which is the git-correct way to create a mirror unless you are a git uberlord.

On your client:

  1. repo init -u # you may use a different means of accessing your git server; I have to assume something for this example.

  2. no repo sync yet. Your manifest is probably wrong. Look at the symbolic linked .repo/manifest.xml… cat it and read at the top the <remote fetch=""… it probably points back to but if it says ‘..’ I think that means ‘come back to my server’, so you can skip to step 6). But if it does point back to another server (not yours), then go to step 3.

  3. cd .repo/manifests
  4. vim .repo/manifests/default.xml (or whatever your active manifest.xml is).
  5. Fix default.xml’s <remote fetch="CHANGE ME" to point back to your git server
  6. attempt a repo sync. It should pull only from your repository. If it doesn’t, stop the repo sync, and try to fix default.xml again.
  7. Once you see repo sync work on your test machine, then commit default.xml back in (git commit; git push), so that others on the team will have ‘no-manifest-edit’ experience when they repo init; repo sync from your server.

Once you see a ‘no manifest edit’ repo init; repo sync work, then go to your default.xml again, and just start adding new XML elements along with the tons of other existing Android project elements; these new elements will point to your custom projects. For these new projects, just git init them as you normally would, and make sure they have a branch matching the same <default revision="whatever_branch_you_see_here" so that a repo sync will succeed when it encounters these new projects.

If you do indeed set a default branch in your manifest <default revision="" element, then just have everyone make a local branch set to follow the remote branch specified in the revision attribute. So, for example, if <default revision="branch_a" is in your manifest, after you do a repo sync, when you cd into a sub-project of interest, do a :

git checkout -b branch_a origin/branch_a

Then, if the user git push‘s (there is no repo command to push, as far as I’m aware), and if someone else does a ./repo sync after that push, they will get those changes from the original user… as long as you are using the same manifest and actually pushing to the default revision (branch) specified by that manifest.

That’s the simplest recipe. If you want to make actual feature branches, then you’ll have to edit your manifest more regularly if you want ‘repo sync’ to just work… and you will have to communicate to the rest of the team to grab your version of the manifest when you do that. Alternatively, if it’s just one or two git repos you are touching, then you could just forego repo sync and git push/pull like normal on those repos and ignore the rest of the quiet tree for the times you are heavily iterating. This sounds, ultimately to me, like a simpler path. I’d ignore repo as much as you possibly can; only using it for ‘all project’ syncs and leaving it alone for the times you are focusing on 1 or 2 projects.

Regarding getting updates from upstream. I think the way to do that is to change your default.xml to point back to your original git location (like, do a repo sync to cause all the new stuff to merge in, and once done with the sync, commit back up to your repo. I haven’t done this yet; so I can’t be too specific, but this is how I plan to do it.

I’m ignoring server administration details above. For instance, you need to call the repo init in a certain directory on your git server to cause it to be an available git repository; I’m assuming you know how to administer your git server.

Leave a Reply

Your email address will not be published. Required fields are marked *