1

Let's say I'm building Android or CyanogenMod from source and want to make changes to its source. Also, let's assume I don't want to submit these changes (since they are incomplete or are changes that have already been rejected, for example).

What is the best way to manage that? How can I have proper source control of my "personal" changes, but at the same time be able to use repo sync so that I have the latest changes?

Can I have local branches (for each project I make changes) and simply merge from the master branch to my local branches after every repo sync?

amfcosta
  • 1,049
  • 10
  • 21

4 Answers4

1

This seems to work for me.

First mentioning some setup

# cd to root of source tree
repo start MyBranch       # Create working branch for all projects
repo checkout MyBranch    # switches all projects to use MyBranch

Time passes, fabulous edits made and committed (in MyBranch), working branch is clean. Now want upstream changes ...

# Current active branch is "MyBranch"
# The following sync -d as per repo docs:
#     -d: switch specified projects back to the manifest revision.
#      Helpful if the project is currently on a topic branch,
#      but the manifest revision is temporarily needed.
# In other words, it automatically syncs default manifest's upstream
repo sync -d -j12

# Active branch may be "MyBranch" or possibly a detached head or whatever.
# So, if necessary, switch back to MyBranch
# - I usually do this just to make sure all projects are in MyBranch
# - NOTE: If a new project appears it won't have MyBranch
repo checkout MyBranch

# Now we're in MyBranch. Its "upstream" is our local master so sync it.
# - This is usually rather quick
repo sync

The "repo sync -d" may not be necessary but hasn't caused any problems as far as I have seen. Plus it pulls the master codeline locally to keep it in sync for handy diffs and such.

Perhaps "repo sync" from within MyBranch does that too. But I don't seem to get any updates when I omit the "repo sync -d" step and just do "repo sync" when MyBranch is checked out. (Although maybe my local setup is messed up somehow)

To summarize:

Option A: Might work

cd RootOfRepoSourceTree   # wherever you have it
repo checkout MyBranch
repo sync

Option B: Works consistently for me

cd RootOfRepoSourceTree   # wherever you have it
repo sync -d -j12
repo checkout MyBranch
repo sync
DevByStarlight
  • 1,070
  • 13
  • 17
0

When you run "repo sync" what actually happens is that each git repository is rebased on a new upstream. If you don't have any local patches in a specific git repository, it's a simple fast-forward. If you do have some patches and upstream does as well(your branch and upstream branch have diverged), repo will attempt an automatic rebase.

So lets say you have a patch on top of upstream code, and upstream has had some new comits since you applied that patch. When you run repo sync, repo will try to rebase your code on top of upstream. If the automatic rebase fails, repo will throw an error message letting you know that you should fix the patch manually.

To sum it up: You can create a branch in each project you want to modify, store your commits on that branch. Repo sync will automatically rebase your patches(unless it fails and then you'd have to apply them manually).

Anton Cherkashyn
  • 5,719
  • 6
  • 43
  • 80
  • I've just tried that (creating a branch and making a commit to that branch). After running repo sync the branch is preserved, but it does not auto merge or rebase upstream on my local branches. Instead it just switches to upstream. – amfcosta May 05 '13 at 00:19
0

You will need to use repo start command to create a topic branch that tracks the remote repo branch. Or you need to use --track option of the git branch command to manually create a local branch with a remote tracking branch. Use the --set-upstream option of the git branch command to add a tracking branch to an existing local branch.

Once you have setup the tracking branch correctly, the repo sync command will fast forward and reapply your local patches as Anton Cherkashyn has described in his answer.

Erdi Chen
  • 46
  • 2
0

Use gerrit in conjunction with repo and git.

Arunabh Das
  • 13,212
  • 21
  • 86
  • 109