How To Set Up Subversion
By Daniel Miessler on September 5th, 2007: Tagged as Development | Programming | Subversion
ext3cow.com
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/dmiessler.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/dmiessler.com -m “Initial Import”
This pulls a copy of your website into your working development directory.
Check Out a Copy to a Temporary Directory Change directory into /tmp and run:
svn co file:///Repository/dmiessler.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 dmiessler.com htdocs
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 System Install subversion on your client and cd into your dev directory (I use OS X).
svn co svn+ssh://user@dmiessler.com/Repository/dmiessler.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 Version Just 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 up
If 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:
Then:include
include
include
int main(void) { execl(”/usr/local/bin/svn”, “svn”, “update”, “/home/joe/publichtml/”, (const char *) NULL); return(EXITFAILURE); }
gcc -o svnupdate svnupdate.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.:



Nice, concise bit on subversion, but why do you create a C++ application for updating when a simple shell script will do? Or even an alias?
Comment by Stretch — 9/5/2007 @ 8:39 pm
The reason for using a c program is that svnserve will run the hooks as the apache user, so you need to create an executable with the setuid bit set. There are other options, such as using groups, but they’re not universally available.
What might be simpler is to use the executable to execv a shell script.
Comment by Jason McCandless — 9/6/2007 @ 6:28 am
You might clarify, in the Import step, is it OK if “.” has files and multiple subdirectories, or should it have only a single subdirectory.
Comment by F.Baube — 9/6/2007 @ 11:05 am
[...] dmiessler.com | How To Set Up Subversion (tags: subversion tutorial development software) [...]
Pingback by Craig Vidler | Weblog » links for 2007-09-07 — 9/7/2007 @ 8:14 am
test bugaga
Comment by test — 9/19/2007 @ 7:44 am
tessssssssssssssssst
Comment by test — 10/1/2007 @ 5:29 am
tterte
Comment by topsmileq — 10/5/2007 @ 6:01 am
Well done, I spent a bunch of time messing around with other more complicated tutorials, found this, and had what I needed in 15 minutes. Thanks!
Comment by Rando — 11/19/2007 @ 6:48 am