- Unsupervised Learning
- Posts
- How To Set Up Subversion
How To Set Up Subversion
Setting up Subversion for revision control can be a bit frustrating. There are a million sites talking about how to do it, but many of them are contradictory and/or overly complex. Here’s a simple approach that works for me every time.
Create Your Repository
svnadmin create /Repository
This utilizes the svnadmin that creates the main directory that your projects will reside in.
Create Your Project
svn mkdir file:///Repository/danielmiessler.com
Notice that you can’t just create this with regular mkdir. You need the svn bit. This won’t create an actual directory under /Repository, by the way. Don’t worry, it’s there. You can view it with svn list file:///Repository.
Populate Your Repository (Import)Go into your web directory and run:
svn import . file:///Repository/danielmiessler.com -m “Initial Import”
This pulls a copy of your website into your working development directory.
Check Out a Copy to a Temporary DirectoryChange directory into /tmp and run:
svn co file:///Repository/danielmiessler.com
This pulls a copy of your website from your development repository to your temporary location.
Move That Temporary Working Copy Next To Your Web Directory Move your temp copy next to your web directory, then go one directory higher than your web directory and run:
mv htdocs htdocs_backup
Make The Switch
mv danielmiessler.com htdocs
Unsupervised Learning — Security, Tech, and AI in 10 minutes…
Get a weekly breakdown of what's happening in security and tech—and why it matters.
This puts your subversion copy of your site where your non-version-controlled version used to be.
Check Out a Copy To Work With On Your Development SystemInstall subversion on your client and cd into your dev directory (I use OS X).
svn co svn+ssh://[email protected]/Repository/danielmiessler.com
This pulls a copy of your repository down to your development machine. Notice that you’ll now have a copy of the site in that directory. This is the version of the site that you’ll be making changes to.
Use TextMate To Edit Your Local VersionJust a recommendation of course, but a strong recommendation. Download and install TextMate to edit your copy of the site. File –> New Project. Drag and drop your site’s directory into the folder pane.Once you’ve made some changes, you can use TextMate’s built-in subversion support. Make a change to your code and then press shift-control-A, which allows you to select “commit” to update the repository.
[Optional] Configure an Automatic svn upIf you don’t do this trick you’ll have to go into the root of your web directory on the server and run svn up to get the changes from the repository into production.
This allows you to bypass that by making use of subversion’s post-commit hook. Essentially, anything in that post-commit hook script gets run right as you check in from the client (commit). So what we do is make use of a little C++ program that will run the svn up for us. Here’s the code:
include
include
include
int main(void) { execl("/usr/local/bin/svn", "svn", "update", "/home/joe/public_html/", (const char *) NULL); return(EXIT_FAILURE); }
gcc -o svn_update svn_update.cpp
Then just point to it from your post-commit script (be sure to remove the template suffix).
So now when you make a change you just commit it and it’s live on the site. All with the protection of being able to roll back your various changes if you need to.: