Even though the Camino source is managed in CVS, you can use Git locally to track the official repository. Doing so offers many advantages to the development process. You can easily work on multiple bugs at once, you can stash your code or make a new branch to perform a review on the side, and you can easily keep your work synchronized on multiple computers.

+

Even though the Camino source is managed in CVS and Hg, you can use Git locally to track the official repository. Doing so offers many advantages to the development process. You can easily work on multiple bugs at once, you can stash your code or make a new branch to perform a review on the side, and you can easily keep your work synchronized on multiple computers.

+

+

'''Warning:''' these instructions were written without the need to commit to the original source repository (CVS or Hg); '''if you are committing to Camino from the git-managed tree, you have to be very, very careful'''.

=Prerequisites=

=Prerequisites=

+

+

This article was originally written when Camino development happened solely in CVS. Currently, Camino development takes place in a Mercurial repository, while some older branches are still in CVS. Generally speaking, these instructions work equally well for interacting with Hg and CVS repositories; simply substitute the equivalent Hg command when a CVS command is provided.

This article assumes you have already checked out a fresh copy of the Camino source. Follow our [[Development:Building|build instructions]] to do this. Note: you don't need to build yet, so after setting things up you can issue the following command to checkout the source only:

This article assumes you have already checked out a fresh copy of the Camino source. Follow our [[Development:Building|build instructions]] to do this. Note: you don't need to build yet, so after setting things up you can issue the following command to checkout the source only:

'''Warning:''' these instructions were written without the need to commit to the original source repository (CVS or Hg); '''if you are committing to Camino from the git-managed tree, you have to be very, very careful'''.

=Appendix: Misc Git tips=

=Appendix: Misc Git tips=

Latest revision as of 20:04, 26 May 2010

How to use Git locally to supercharge your Camino development workflow.
by Sean Murphy
on 2009-03-23

Even though the Camino source is managed in CVS and Hg, you can use Git locally to track the official repository. Doing so offers many advantages to the development process. You can easily work on multiple bugs at once, you can stash your code or make a new branch to perform a review on the side, and you can easily keep your work synchronized on multiple computers.

Warning: these instructions were written without the need to commit to the original source repository (CVS or Hg); if you are committing to Camino from the git-managed tree, you have to be very, very careful.

Prerequisites

This article was originally written when Camino development happened solely in CVS. Currently, Camino development takes place in a Mercurial repository, while some older branches are still in CVS. Generally speaking, these instructions work equally well for interacting with Hg and CVS repositories; simply substitute the equivalent Hg command when a CVS command is provided.

This article assumes you have already checked out a fresh copy of the Camino source. Follow our build instructions to do this. Note: you don't need to build yet, so after setting things up you can issue the following command to checkout the source only:

$ make -f client.mk checkout MOZ_CO_PROJECT=macbrowser

Note: Throughout the article /PathToCaminoSource/ is the directory that contains a mozilla/ subfolder with the source tree, and a CaminoObj/ folder for all the build objects.

Installing Git on Mac OS X

The short and sweet steps to install Git on the Mac:

Note: Replace the "1.6.2.1" Git version below with the most current release. Check http://git-scm.com/ to find out what the current revision is.

Excluding certain files from being tracked by Git

Just like .cvsignore and Mozilla's .hgignore, we'll create an ignore file for Git to exclude certain files we do not want it to manage.

Exclude files for all repositories

You can create a global ignore file to always exclude files from any Git repository on your machine. In here we'll list certain Mac development related files we'll never want Git to see and ask us if we want to track it.

Save this file as ~/.gitignore

.DS_Store
*.orig
*.rej
*~
# The following ignores all files in the .xcodeproj bundle,
# And then adds back in only the project (skipping the user files)
*.xcodeproj/
!*.xcodeproj/project.pbxproj
*~.nib
*.swp
*.o
.#*
a.out

Then, we have to configure Git to use our global excludes file:

$ git config --global core.excludesfile ~/.gitignore

Exclude Mozilla specific files

Git will also look for a .gitignore file in the root directory of each repository. In here we can exclude additional files that are specific to Camino development, ones that we would not want to ignore across the entire system.

Day to day Camino development with Git

Now, this is where the real fun begins, and when you notice that all the above setup was extremely worth the effort!

Creating a branch to work on a bug

Git, by default, will create a master branch. This is where I keep the official, untouched source from Camino's CVS repository.

When I want to begin work on a certain bug, I will create a new branch. The following command is a shortcut to create a new branch and also check it out:

$ git checkout -b NameOfCurrentBug

Now, you can edit away. Anytime you need to switch contexts, maybe to work on a different bug that suddenly came up or to step aside and review a patch, you can just keep creating branches to do this:

$ git checkout -b NameOfCurrentBugToReview master

You can list the branch you want to stem from as the last argument. In this case, we weren't on the master branch, so we explicitly told Git to branch from there rather than defaulting to the current one.

Staying in sync with the Camino CVS repository

Your Git repo's master branch is our mirror to the pristine CVS source. Whenever you want to sync with the official Camino repository, just checkout your master branch, perform an update through CVS, and commit the changes:

Incorporating the latest CVS changes into your working branches

We now have pulled the latest CVS updates into Git, but the branches that we're working on need to be merged with the latest updates as well, which are kept on the master branch. For this, we can use the git rebase command.

$ git checkout NameOfBugBranch
$ git rebase master

You can read more about git rebase, and how it differs from git merge.

Working on multiple Macs

One of the other huge advantages of using Git locally is that it easily makes it possible to develop the same feature across multiple machines, keeping all of your work in sync.

When you clone, Git sets up a remote corresponding to the original machine, called origin. You can use this remote identifier to push and pull updates to and from your other Mac.

To check out branches that you had on the other machine:

(SecondMac)$ git checkout -b BranchName origin/BranchName

Branch BranchName set up to track remote branch refs/remotes/origin/BranchName.

This output means that Git automatically configured this new branch as a "tracking" branch, and any remote operations will know to work against the branch on the original machine. Learn more about what that means here.

Edit files, then commit the changes locally:

$ git commit -am "Changed a few files"

Push my updates back onto the other machine where we cloned from:

$ git push

Or, on the other end, use git pull and git fetch on the original machine. See the community Git book for more information about the distributed workflow in Git.

The Gotcha: Communicating with CVS on your other Mac

Our Git repository does not track or keep a copy of the CVS metadata. This means that when we clone the repository onto another machine, we are unable to actually sync or otherwise communicate with Camino's CVS repo on any secondary machine. Tracking the CVS/ information creates too much noise in the Git repository and I haven't found any sane way to keep this data in Git.

Therefore, anytime you need to interact with the official CVS repository, it has to be done on the original machine. To sync with upstream changes on the Camino trunk, you first need to cvs update on the original Mac commit the changes into the master branch like always (this can be done over SSH since you're remote). Then, you can then git fetch/pull the updates through origin/master branch on your remote repository.

Performing cvs diff and creating patches must also be done on the original machine, unfortunately. To do this, just push or pull your changes onto the machine with the original repository (and CVS information), and then perform a cvs diff from the Git branch your changes are on. (It is possible to perform a diff with Git, from your working branch to a freshly synced master, but the patch will appear like it's from Git and I'm not sure if this is acceptable or not, so I usually just do the regular CVS routine).

Automatically updating Camino.xcodeproj when switching branches

When switching back and forth between branches, the working copy of the Camino Xcode project will become out of sync. This is because it's kept in $OBJDIR/camino and Git is managing and modifying files in the source directory ($topsrcdir/camino).

You can use a Git hook to automatically update the Xcode project in the objdir when a checkout command is performed. This is for most times when a complete rebuild (using make in $OBJDIR/camino) is not necessary, but rather just a sync of Camino.xcodeproj.

The steps to create a hook are simple:

In your Camino git repository, go inside the .git folder. Then, you'll see a hooks subfolder inside of there. Create a new file titled "post-checkout" with the following contents:

Finally, make the file executable. (Note I use the "-v" argument to let cp give me some feedback that the copy is taking place. This explicitness means I won't forget the hook is in place and wonder a month later what's going on!)

Now, whenever you switch branches your working copy of the Xcode project will stay in sync with any changes in the given branch.

Committing to the Camino repository

Warning: these instructions were written without the need to commit to the original source repository (CVS or Hg); if you are committing to Camino from the git-managed tree, you have to be very, very careful.

Appendix: Misc Git tips

Bash enhancements for use with Git

Tab completion

Git includes a bash script that offers tab-competion of commands, branch names, etc. It's easy to install and a joy to have.

Look for the "git-completion.sh" file. It is usually found in git-x.x.x.x/contrib/completion/, but I think recently a Git patch has it moving to /usr/local/share/git-completion/ during installation.

Copy this file to somewhere (e.g. ~/.git-completion.sh).

Added the following line to your .bashrc:

source ~/.git-completion.sh

Branch name in prompt

Additionally, it is extremely helpful to also have your bash prompt list the current branch you are on. Enable this by doing the following: