PHP Objects, Patterns and Practice (3rd edition)

(Barry) #1
CHAPTER 17 ■ VERSION CONTROL WITH SUBVERSION

Before you start, take a good look at your files and directories, removing any temporary items you
might find. Failure to do this is a common and annoying mistake. Temporary items to watch for include
automatically generated files such as phpDocumentor output, build directories, installer logs, and so on.


■Note You can specify files and patterns to ignore during import, commit, and update by editing the


configuration file that the Subversion should have created in your home directory at .subversion/config. Look


for an option called global_ignores, which will probably need to be uncommented. It should provide examples of


filename wildcarding that you can amend to exclude the various lock files and temporary directories created by


your build processes, editors, and IDEs.


Once your project is clean, it’s time to think about how you’re going to organize your versions.
Subversion allows you to manage multiple versions of your project. You can easily branch the project to
create new versions, and then merge your changes back from whence they came. Although there is
nothing to stop you organizing your versions as you wish, there are some conventions that many
developers observe. Typically, you will elect to keep a single 'main' line of development as the source
and eventual destination of all branches. This branch is known as the trunk. In fact, thanks to
Subversion’s flexibility, this will simply be a directory named trunk. You also need a directory in which
you can save your branches. If you’re following the convention, you’ll call this ‘branches.’ Finally, you
might need a place to save snapshot branches. These are not different in nature from any other kind of
branch, but their purpose is to provide a snapshot of a particular moment in a project’s evolution, rather
than a site for parallel development. These should be saved to a directory called tags.
You can move directories around the repository after import, but because I know what I want at
import time, I might as well set up my directory structure first. If my directory structure looked like this:


megaquiz/
quiztools/
commands
quizobjects/


I might add another layer of directories before import, so I end up with this:

megaquiz/
branches/
tags/
trunk/
quiztools/
commands
quizobjects/


As you can see, there’s nothing magic about branches and tags. They are just regular directories.
With everything in place, I can finally import my project:


$ svn import megaquiz svn+ssh://localhost/var/local/svn/megaquiz


Let’s break down this use of the Subversion command. Subversion is a very big package consisting
of many subcommands and switches. import requires a URL argument that points to the new directory
on the server. The directory name is essentially the project name. As you can see, the import
subcommand also accepts a path to the directory you wish to import. If you don’t specify this, Subersion
will import the current working directory.

Free download pdf