In Part I, I walked through the process of setting up repositories and projects in Subversion, Part II covered configuring Subversion with Xcode, this part will provide an overview of the SCM tools within Xcode and also show you how to tag and branch your code within Subversion.
Xcode SCM Attributes
If you have your project successfully configured for use with Subversion, once you check-out your files and make any changes Xcode will identify these changes with attributes. Once you start editing a file, an ‘M‘ will show up next to the file in the Groups & Files window. Also, if you add any files to your project these will be identified with a ‘?‘. These attributes will remain until your changes are committed or if you discard your changes.
Committing & Discarding Changes
If you are familiar with other version control systems, you might know committing as ‘check-in’ and discard as ‘undo check-out’. You can commit or discard changes at the file level by right-clicking each file or folder and making the selection or by selecting ‘SCM‘ from the menu and selecting commit or discard changes. The ‘SCM‘ menu also allows you to commit all the changes in your project by selecting ‘Commit Entire Project‘.
Other SCM Tools
The Xcode SCM Menu provides a couple of ways to easily compare the contents of any file that you have checked-out with any revisions committed in Subversion, using FileMerge and the Unix diff tool.
Compare
By selecting ‘Compare With’ from the ‘SCM‘ menu, Xcode will open the FileMerge application that will show each file side-by-side and indicate the differences between each file. In File Merge, you can choose to add or remove any lines in your checked-out file.
Diff
If you have had exposure to the diff tool in Unix/Linux, it is available as an option to use within Xcode. By selecting ‘Diff With‘ from the ‘SCM‘ menu, Xcode will execute the diff command with your currently checked-out file and the revision file that you specify as arguments. The results of this command will be displayed in the current code window.
Subversion Tagging
In Part I, I mentioned that Subversion also has the following folders: tags and branches. The tag folder is used for storing releases or stable builds of your code and allows you recall the correct version of the project files if you need to fix any bugs. Here is a script that will allow you to tag your project, it assumes that whatever the is currently committed in the trunk folder is what you want to tag:
# A script to tag a SVN release
reporoot=/Library/Subversion/Repository/
projdir=Projects
# Prompt for repository name
print -n "Enter repository name:"
read repo
# Prompt for project name
print -n "Enter project name:"
read project
# Prompt for release number
print -n "Enter release number:"
read release
# Tag release
svn copy file://$reporoot/$repo/$projdir/$project/trunk file://$reporoot/$repo/$projdir/$project/tags/release-$release -m "Tagging the $release release of the ‘$project‘ project."
echo
echo Tagging the $release release of the $project project Complete!
echo
Subversion Branching
The branches folder is used for storing code that you want to develop new functionality with or experiment on without making revisions to the code in the trunk. Here is a script that will allow you to branch your code, also it assumes that whatever the is currently committed in the trunk folder is what you want to branch.
# A script to branch a SVN trunk
reporoot=/Library/Subversion/Repository/
projdir=Projects
# Prompt for repository name
print -n "Enter repository name:"
read repo
# Prompt for project name
print -n "Enter project name:"
read project
# Prompt for branch name
print -n "Enter branch name:"
read branch
# Create branch
svn copy file://$reporoot/$repo/$projdir/$project/trunk file://$reporoot/$repo/$projdir/$project/branches/$branch -m "Creating a branch of the ‘$project‘ project."
echo
echo Creating a branch of the $project project Complete!
echo
I hope you enjoyed reading this 3 part tutorial on setting up Subversion within Xcode. Please share your thoughts on how you use Subversion or any other SCM system with your development environment.


One Comment
Good article. Two questions;
1) Once a branch is made, changes are done and tested, how is the branch merged back into the trunk?
2) The XCode GUI has “copy” capabilities, how is the different than the command line svn copy command? Does the GUI have an equivalent to the -m option?
One Trackback
[...] Using Subversion with Xcode, Part III [...]