header

Making a webroot a Subversion Repository



So I setup a Subversion repository successfully. Well, turns out it wasn’t complete.

My client would like to access and change files via Subversion instead of what they were currently using, FTP. Moreover, they would like the files to exist in their webroot of their domain. Their project is a web project, after all.

After some research and discussion with peers, I found out how to do this. First, I had to add their directory as accessible via subversion. I used Subversion’s FAQ about in-place import to do what I needed. My exact commands were:
# svn mkdir file:///home/svn/rep/{repname}/domain.com -m "Initial create"
# cd /home/{user}
# svn checkout file:///home/svn/rep/{repname}/domain.com
# svn add *
# svn commit -m "Initial version of files"

That seemed to work great, the repository was setup! My client had access to read and write files to their repository, which is their webroot. However, the webroot doesn’t auto-update, so any changes won’t take effect unless it’s manually updated.

Reading further in the Subversion FAQ, I found a way to auto update the files on the website.
I created a “Tiny C” app with the following code
#include <stddef.h>
#include <stdlib.h>
#include <unistd.h>
int main(void)
{
execl("/usr/local/bin/svn", "svn", "update", "/home/{user}/domain.com",
(const char *) NULL);
return(EXIT_FAILURE);
}

Then compiled it

cc -o updaterepo postcommit.c

Then made updaterepo executable and gave it chmod +s, as suggested by the FAQ. Of course I made it owned by {user} as well. Then I created /home/svn/rep/{repname}/hooks/post-commit with the following content

#!/bin/sh
/home/{user}/updaterepo

I tested a commit, and it worked!



3 Comments »

  1. gravatar

    Gabe Said,

    February 2, 2007 @ 12:29 pm

    Why didn’t you just put the svn update command directly in the post-commit file?

    That’s pretty cool that subversion supports post commit actions.

  2. gravatar

    Raybdbomb Said,

    February 2, 2007 @ 12:34 pm

    The faq explains that…

    If the server needs to update a working copy that it doesn’t own (for example, user joe’s ~/public_html/ area), one technique is create a +s binary program to run the update, since Unix won’t allow scripts to run +s.

  3. gravatar

    Raybdbomb Said,

    March 29, 2007 @ 11:54 am

    The only reason the post commit hook fails, that I can tell, is if the permissions aren’t right on the files in the repository. That happens for me when I manually svn update as a different user.

RSS feed for comments on this post · TrackBack URI

Leave a Comment

blogtimes