When you start learning new languages and work through different projects and problems, I find it helpful to have my code under version control (or SCM). Keeping on topic with my previous post about learning iPhone Application Development, it may be a good idea to version your code especially when working with the Stanford University projects. Currently Xcode supports three different SCM tools: CVS, Perforce and Subversion. You may choose to setup either tool, I have chosen Subversion because of its ability to integrate with a variety of development IDEs: Xcode, Visual Studio, Eclipse, NetBeans, etc.
The most detailed resource I have found on setting up Subversion within Xcode 3.1 is from the Apple Developer Connection. In this post I will keep it simple, as well as, provide shell scripts so you can avoid typing tedious commands to add new projects, branch, tag, etc.
This configuration will use svnserve, which is a lightweight Subversion server useful for individual developers, it is also installed by default on OS X. If you are looking to setup Subversion in a large development environment with multiple users, the Apple Developer Connection document will provide details for setting up Subversion with Apache.
This tutorial will cover the initial setup of configuring your Subversion repository and creating your first project via the command line.
Creating a Repository
A repository is the data store that will contain all of your projects. Because Xcode will only allow you to have one project folder at the root of the repository, I create a Projects folder that will contain all my individual projects. The following script will create your repository and a projects root folder:
# A script to create a new SVN repository
# Set this to the location where you want to store your repositories
reporoot=/Library/Subversion/Repository/
# This is the name of the projects root folder
projdir=Projects
# Create new repository
print -n "Enter new repository name:"
read repo
echo
echo Creating repository $repo
svnadmin create $reporoot/$repo
echo
echo Creating projects directory
svn mkdir -m "Directory for Projects" file://$reporoot/$repo/$projdir
echo
echo Repository Creation Complete!
echo Start adding new projects
echo
Creating a Project
The structure of a project in Subversion is setup with three sub-directories: branches, tags, and trunk. Each of these are used for the following:
Trunk
This is the location where you will import all your project files. The files contained in this folder will be the those that are checked-out and committed (checked-in).
Tags
This is the location where you will archive your releases of your project.
Branches
If you need to experiment with changes to your project and do not want to make changes to the files in the Trunk, the Branches folder is where you can store these project files.
This script will automate a lot of the work of creating the folders above. You can run this script each time that you need to add a new project to your repository.
# A script to create a new SVN project directory
# Replace this with the path of your Repository and Projects folder
reporoot=/Library/Subversion/Repository/YourRepositoryName
# Create new project
print -n "Enter new project name:"
read project
# Clean up local tmp directory
rm -rf /tmp/project
echo
echo Creating temporary directories
mkdir -p /tmp/project/$project/trunk /tmp/project/$project/branches /tmp/project/$project/tags
echo
echo Importing $project into Subversion
svn import /tmp/project/ file://$reporoot -m "Initial import"
echo
echo Cleaning up…
rm -rf /tmp/project
echo
echo "Directories Created!"
echo "Import your project through SCM in Xcode"
echo
Part II, will cover configuring Xcode to connect to add your project files to your Subversion repository.
2 Trackbacks
[...] « Using Subversion with Xcode, Part I Using Subversion with Xcode, Part III [...]
[...] Part I, I walked through the process of setting up repositories and projects in Subversion, Part II [...]