LogoPhly, boy, phly
the weblog and site of Matthew Weier O'Phinney

Monday, August 31. 2009

Cloning the ZF SVN repository in Git

I've been using Git for around a year now. My interest in it originally was to act as a replacement for SVK, with which I'd had some bad experiences (when things go wrong with svk, they go very wrong). Why was I using a distributed version control system, though?

  • I travel several times a year for work. Oftentimes I have long layovers, or hotels and/or conference venues with spotty or pricey internet connectivity. I need a way to continue working such that I can continue making atomic commits without needing to worry about whether or not I have network access.
  • I work from home. This gives me great flexibility in terms of where I work. Sometimes I work from the laundromat -- and when I do, I often bring a list of bugs I want to work on. However, the laundromat I go to has no connectivity. (This is a good thing, as far as I'm concerned; I'm forced to concentrate on nothing but my list of bugs.)
  • Merges. Subversion is a great tool, but merging can be oftentimes painful. The tools in git for merging are incredible, and it's rare that I run into conflicts. Subversion, on the other hand... oof. While I can fix conflicts relatively easily, I like to avoid them in the first place. If you need convincing, try "git cherry-pick" sometime.
  • Ease of installation. The ZF sources take a lot of disk space, and when I have multiple branches, trunk, and the incubator checked out, the size balloons. Additionally, it gets crazy trying to determine what to put on the include_path, particularly when running tests.
  • Prototyping. I often like to work in an experimental branch where I know I won't conflict with anyone else -- but also don't care about the commit history so long as I merge in the changes I need to trunk. With subversion, I have to create a branch, which means adding to the repository history needlessly.

Git's svn integration provides a featureset that answers all of my concerns. Additionally, the ability to clone a git+svn repository locally allows me to have multiple versions available at any given time -- which can be tremendously useful when needing to diff tags, test sites against different versions, etc.

The easiest way to clone an svn repository for use with git is to use either "git svn init" or "git svn clone". With both of these, you point git to an SVN repository and tell it some information about the layout (where trunk is, and where the branches and tags are), and it creates a local git repository that remotes to the svn repository. As an example:


% git svn init --trunk=trunk --tags=tags --branches=branches http://framework.zend.com/svn/framework/standard
 

The above would initialize a git repository in the current directory pointing at the ZF standard repository. You can simplify the switches to simply "--stdlayout", as the above reflects the standard Subversion recommendations for repository layout.

Note: I used "git svn init", followed by "git svn fetch". This allowed me to specify a revision I wanted to start my repository from. Trust me: you do not want to try and clone the entire ZF repository. Besides the size of the repo, we also changed the layout mid-May 2008 -- which makes cloning problematic. Initialize and fetch from a more recent revision; I've personally rebuilt my checkout a few times, most recently dating from the 1.8.0 release at the end of April 2009.

There's one place that ZF differs, however, that has posed a problem for me: the incubator. We have placed the incubator as follows:

standard
|-- branches/
|-- incubator/
|-- tags/
`-- trunk/

In other words, it's a sibling to "branches", "tags", and "trunk" -- and doesn't fit the normal paradigms. My problem has been how to inform git about its location.

The answer proved incredibly simple. In the repository's ".git/config" file, you will have the following after repository intialization:


[core]
        repositoryformatversion = 0
        filemode = true
        bare = false
        logallrefupdates = true
[svn-remote "svn"]
        url = http://framework.zend.com/svn/framework
        fetch = standard/trunk:refs/remotes/trunk
        branches = standard/branches/*:refs/remotes/*
        tags = standard/tags/*:refs/remotes/tags/*
 

To add the incubator, we add an additional svn-remote, point it to the incubator, tell it where to start fetching commits, and then checkout the new branch.

First, to add the new svn-remote, simply add the following lines to the above ".git/config" file:


[svn-remote "incubator"]
    url = http://framework.zend.com/svn/framework/standard/incubator
    fetch = :refs/remotes/svn-incubator
 

Then, fetch svn commits on the incubator remote from a given commit; I used r15241 myself:


% git svn fetch incubator -r 15241
 

Then, checkout the incubator branch locally. This works just like any other remote branch -- you check out a local branch, and indicate the remote to utilize:


% git checkout -b incubator svn-incubator
 

The above creates a local "incubator" branch that points to the "svn-incubator" remote created in the config file earlier.

Finally, pull in all other commits since that revision using the standard svn rebase:


% git svn rebase
 

From this point, you can now switch back and forth between the incubator, trunk, and any other branches you've created by simply using "svn checkout <branchname>".

For those of you ZF developers who are using git or considering doing so, I hope this post helps. If you're interested in trying it out, I can also provide a tarball of my own repository; drop me an email if you're interested (be aware, though, it's not small...).

Posted by Matthew Weier O'Phinney in PHP at 12:54 | Comments (5) | Trackbacks (0)
Defined tags for this entry: git, php, zend framework
Related entries by tags:
Module Bootstraps in Zend Framework: Do's and Don'ts
Responding to Different Content Types in RESTful ZF Apps
Symfony Live 2010
Creating Re-Usable Zend_Application Resource Plugins
Quick Start to Zend_Application_Bootstrap

Trackbacks
Trackback specific URI for this entry

No Trackbacks

Comments
Display comments as (Linear | Threaded)

Thanks for this! What are the chances there will be an "official" ZF clone on GitHub someday? ;-)
#1 Bradley Holt (Link) on 2009-08-31 13:37 (Reply)
Not sure; depends on whether we want full history, or just going back to the migration. I also need to investigate how somebody can push commits back via the git+svn bridge, assuming they have commit rights.

That said, I know plenty of folks would like to see it, and the nature of git makes it simple to integrate one project into other projects -- ideal for most web development, really.
#1.1 Matthew Weier O'Phinney (Link) on 2009-08-31 13:41 (Reply)
The downside of this is that you can't have both the incubator and the core library on the include path at the same time, right?

I'm setting up git for ZF's svn repo now, and I'd like to use classes from both libraries (core and incubator) at the same time. Looks like I have to to for a separate git project with the incubator. The only problem with this is moving things between the incubator and trunk. Luckily, that's not something I have to be concerned with in ZF :-)
#2 Robin Skoglund (Link) on 2009-09-19 14:46 (Reply)
Actually, what I've done is to create clones from my master git repo that I maintain elsewhere. Those can then be on my include_path, and I can update them periodically with a "git pull". :-)
#2.1 Matthew Weier O'Phinney (Link) on 2009-09-20 07:55 (Reply)
Ah, of course! That's way cooler than having two separate git-svn setups. Thanks :-)
#2.1.1 Robin Skoglund (Link) on 2009-09-20 07:58 (Reply)

Add Comment

Standard emoticons like :-) and ;-) are converted to images.
E-Mail addresses will not be displayed and will only be used for E-Mail notifications

To prevent automated Bots from commentspamming, please enter the string you see in the image below in the appropriate input box. Your comment will only be submitted if the strings match. Please ensure that your browser supports and accepts cookies, or your comment cannot be verified correctly.
CAPTCHA

 
 
  • Home
  • Resume
  • Blog
  • Phly PEAR Channel
  • Contact Me
  • About this site

ZCE

Zend Education Advisory Board Member

Add to Technorati Favorites

Calendar

Back March '10 Forward
Mon Tue Wed Thu Fri Sat Sun
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31        

Quicksearch

Links

  • PHLY - PHp LibrarY
  • Paul M. Jones
  • Mike Naberezny
  • Shahar Evron
  • Planet PHP
  • Zend Where I now work
  • Garden.org Where I once worked

Archives

March 2010
February 2010
January 2010
Recent...
Older...

Categories

XML Linux
XML Personal
XML Aikido
XML Family
XML Programming
XML Dojo
XML Perl
XML PHP

All categories

Syndicate This Blog

XML RSS 0.91 feed
XML RSS 1.0 feed
XML RSS 2.0 feed
ATOM/XML ATOM 0.3 feed
ATOM/XML ATOM 1.0 feed
XML RSS 2.0 Comments

Show tagged entries

xml best practices
xml books
xml conferences
xml cw09
xml decorators
xml dojo
xml dpc08
xml file_fortune
xml git
xml linux
xml mvc
xml oop
xml pear
xml perl
xml personal
xml php
xml phpworks08
xml programming
xml rest
xml ubuntu
xml vim
xml webinar
xml zendcon
xml zendcon08
xml zendcon09
xml zend framework
© 2004 - present, Matthew Weier O'Phinney
matthew-web <at> weierophinney.net