Peter's Blog

Redefining the Impossible

Subversion Notes


I have put my drupal stuff under subversion for some source control so I can unify the source of three separate installations. In theory I could use drupal's virtual hosting features and have a single set of drupal files but:

  • I want these installations to have seperate files and images directories and drupals virtual hosting does not support this
  • I want apache2 to control all my virtual hosting.
  • I want my own drupal hacks under source control

Some notes on how I did this:

  • Create temporary copies of files I want submitted to subversion:
    mkdir ~/drupal
    mkdir ~/drupal/trunk
    cp -r /var/www/petersblog.org/* /var/www/petersblog.org/.htaccess ~/drupal/trunk
    
  • remove stuff I don't want shared with other drupal installations:
    rm -r ~/drupal/trunk/files
    rm -r ~/drupal/trunk/images
    rm -r ~/drupal/trunk/sites
    rm -r ~/drupal/trunk/favicon.ico
    
  • Put into subversion:
    svn import ~/drupal file:///repository_name/drupal -m "First Import"
    
  • Get out of subversion again:
    mkdir /var/www/petersblog2.org
    cd /var/www/petersblog2.org
    svn checkout file:///repository_name/trunk/drupal .
    
  • Since that worked ok, the copies of the files I created to put into subversion can now be zapped:
    rm -r ~/drupal
    
    If there is one thing I do not like about subversion it is this 'trunk' directory thing. I know it is not a requirement but just a convention but still.
  • restore non-archived files
    cp -r /var/www/petersblog.org/files /var/www/petersblog2.org/files
    cp -r /var/www/petersblog.org/images /var/www/petersblog2.org/images
    cp -r /var/www/petersblog.org/sites /var/www/petersblog2.org/sites
    cp -r /var/www/petersblog.org/favicon.ico /var/www/petersblog2.org
    
  • set up subversion to ignore these files that I don't want under svn control. After this running svn status will not list these files and subversion will not attempt to add them to the archive:
    svn propedit svn:ignore .
    files
    images
    sites
    favicon.ico
    
  • commit changes, namely the changes to the svn:ignore properties
    svn commit -m "Ignore files I do not want shared"
    
  • make sure my new copy has everything:
    diff -r --exclude=.svn /var/www/petersblog.org /var/www/petersblog2.org
    
  • change to the new site archive
    cd ..
    mv petersblog.org petersblog_presvn.org
    mv petersblog2.org petersblog.org
    
  • list anything that has changed:
    cd /var/www/petersblog.org
    svn status
    
  • Get the code out on a new site:
    mkdir /var/www/newsite
    cd /var/www/newsite
    svn checkout file:///repository_name/trunk/drupal .
    
  • After modifying the archive, get latest code out of subversion:
    svn update
    
  • Put changes to code into subversion:
    svn commit -m "did some hacking"
    

this cheat sheet was useful.


Filed under: drupal subversion

5 Comments

Dave Says:

over 4 years ago

Hey Peter, saw your post on planet drupal. Wanted to comment to you about svn's trunk folder, because you wrote: "If there is one thing I do not like about subversion it is this 'trunk' directory thing."

I would have done the following:

> mkdir ~/proj

> cp -r /var/www/petersblog.org ~/proj/trunk

> svn import ~/proj file:///repository_name/petersblog -m "First Import"

Then when you need to checkout:

> svn checkout file:///repository_name/petersblog/trunk drupal

So your working directory is called 'drupal' and contains the same files as in your instructions. But in your repository the root directory is called trunk, not trunk/drupal. Later when your project gets complicated you may create branches/drupal-branch-1 or whatever. In svn the branches and tags should be named, but the trunk is simply the trunk. And branches, tags and trunks are all in one directory named after the general project (petersblog in this case).

That's my understanding, anyway. I have a setup similar to yours.

Peter Says:

over 4 years ago

I see the subtle difference: by using

cp -r /var/www/petersblog.org ~/proj/trunk

you have created proj/trunk/petersblog.org/* whereas I put my files directly in proj/trunk

I am no expert in subversion, very much a beginner, the way I did it came from the subversion book where the files go directly in the trunk directory:

Next, create a tree of files and directories to import into the repository. For reasons that will be clear later on (see Chapter 4, Branching and Merging), your structure should contain three top-level directories named branches, tags, and trunk:

/tmp/project/branches/
/tmp/project/tags/
/tmp/project/trunk/
               foo.c
               bar.c
               Makefile

Peter

Peter Says:

over 4 years ago

Actually there is a typo in this line:

svn checkout file:///repository_name/trunk/drupal .

It should be:

svn checkout file:///repository_name/drupal/trunk .

I didn't have the trunk in the root of the repository but I was trying to get it out from there.

Peter

dave Says:

over 4 years ago

(side note: should I be able to log into your site using my drupal account? Is your site invitation only?)

To be clear, I was suggesting that 'trunk' in your repository contain all the project files directly. That is, it should not contain a subdirectory. Your first post implied that your 'trunk' contained a single directory. But your most recent comment explains the typo. That's all I was pointing out.

If you don't like the name 'trunk', its just a convention. You could instead use a name specific to your project. The only really bad choices of name would be 'branches' or 'tags'.

-Dave

Peter Says:

over 4 years ago

I am unclear of the advantages of allowing other drupal users to log into this site, apart from their names in comments being verified. I'm just being a bit paranoid that's all.

I do understand that the trunk thing is just a convention in the way that subversion is used, it is not hard wired into subversion in any way.

Thank you for you advice, I do appreciate it.

Peter

Sorry but comments on this post are now closed.