Difference between revisions of "Subversion"

 This article or section may require a cleanup.We are hoping to create articles that meet certain standards. Please discuss this issue on the talk page. Editing help is available.

Subversion (official site) is a version-control system that keeps track of changes in your files on a server. Subversion helps to coordinate work among multiple people. For an introduction - read the book - it is really great.

Subversion on DreamHost

For Subversion hosting, DreamHost is notable in that it is the only web host providing potentially unlimited storage in Subversion for a flat fee, or at least (now that other web hosts are starting to get into offering Subversion) the web host who was offering huge inexpensive Subversion storage years before any other web host (since at least 2006). And DreamHost's speed in serving Subversion seems quite usable & respectable: since about 2009 July I User:CaydenMC have used DreamHost Subversion for text editing (writing, coding, spreadsheets) with no speed nor space problems what-so-ever.

At DreamHost, you can install and configure Subversion repositories very easily from DreamHost's Subversion Control Panel. As of today 2010.04.09, that gives you the ability to:

1. create/delete any number of repositories
2. create/delete any number of users (with write access) and set/change the password of each,
3. specify if the repository is public and to require/offer http and/or https access,
4. (very cool) specify if the repository available via WebDAV thanks to SVN's Autoversioning which then allows you to conveniently access SVN via WebDAV clients.

In short, DreamHost's Subversion Control Panel is a great way to get started with basic SVN and say test Subversion's speed on DreamHost. However,

1. DreamHost's Subversion Control Panel has serious limitations for say for all but a small number of users (for instance as implied by one customer's suggestion to allow a user to create & update his/her own Subversion account plus to be able to delegate specifying who can access what as allowing each user to have space for which he/she can specify who gets access there). Indeed, in DreamHost's Customer Suggestions, there are several customers asking for this ability. Some customers ask for the general feature, plus there are number of customers (including me User:CaydenMC) asking DreamHost provide a standard SVN front-end which provides for needs such as these and more, as one suggesting the open-source http://USvn.Tigris.Org, and another suggesting Crowd, and another suggesting open-source http://Insurrection.Tigris.Org and there are even more available web admin GUIs for Subversion.
2. The version of Subversion which DreamHost pre-installs is still out-of-date today 2010.04.09: it's been an outdated version at least a year or more, and seemingly has been out-of-date for most of the last 4 years (since 2006) and maybe longer, though not all but some of this MAY be necessary for reliability, as detailed next in #Versions of Subversion on DreamHost.
3. Keep an eye on DreamHost's Customer Suggestions for Subversion and for SVN for more ideas on what Subversion users are into & wanting.

Versions of Subversion on DreamHost

Most (over 80%) current customers, including all customers who signed up after mid-2008, should be on newer machines (in the "homie" cluster), and should have Subversion 1.5 available. Older customers may be on machines with Subversion 1.4 — if you are on such a machine and need a newer version of Subversion, contact Support to request to be moved to a newer machine.

As of April 2010, Subversion 1.6 is available from Subversion's web site, but is not yet available on Dreamhost servers because it is not yet available in Debian Etch. Installing a newer version Subversion manually will make the command-line tools available to your user, but will not cause your repository to be served as SVN 1.6; as such, this approach is not recommended by Dreamhost.

Quick Start

To set up a Subversion repository at svn.yoursite.com for a project called "myproject", follow these steps:

1. Create svn.yoursite.com:
1. Go to your DreamHost control panel and click Domains, then Manage Domains
2. Click Add New Domain / Sub-Domain
3. Enter "svn.yoursite.com" in the Domain To Host field, enter "svn.yoursite.com" in the Web Directory field, and select Remove www.
4. Click Fully Host This Domain Now!
2. Wait a few hours until the new DNS information propagates (that is, when visiting svn.yoursite.com in a web browser doesn't give an error--the page will look like an empty directory listing once the DNS info has propagated).
3. Set up a Subversion repository:
1. Click Goodies, then Subversion
2. Enter "My Project" in the Project Name field, "myproject" in the Project ID field, and make sure that svn.yoursite.com is selected for the URL. Use "myproject" as the directory name.
4. Click Create My New Project Repository Now!

As soon as the DreamHost Subversive Robot actually creates your repository, you can begin using it. For instance, to import a directory:

svn import some_directory http://svn.yoursite.com/myproject -m "Initial import"

You can create additional users for your Subversion project at any time by going to Goodies, Subversion and editing the project. Using this method, users cannot change their own passwords.

Gotchas

Warning: If you create a new repository at an existing domain, AND the domain has been hosted with DreamHost since sometime before 2009(?) the domain may be moved to a new Apache service and the DNS information will change. This will affect you if you have your DNS info hosted somewhere else than Dreamhost (you'll have to get the new IP address and update your DNS info).

Warning: If you are getting 301 errors saying "repository has been moved permanently to [some other url]", then check these things:

• Make sure that you haven't created your repository called "svn" or inside of a directory called "svn".
• Make sure you don't have .htaccess rules above the subversion directory that are causing any kind of re-write (like WordPress)
• * This includes having Dreamhost automatically add 'www.' to your URL. In Domains -> Manage Domains, clicking on edit hosting, you have a choice with regards to "www". Selecting the 'Add WWW' option will result in a 301.

Troubleshooting: If you are getting weird errors and import or checkin is working for some but not all files, double check and try disabling your anti-virus software. See this post for more info http://old.nabble.com/Propfind-200-ok-error-td20063285.html

Warning: Repositories don't act like normal directories: You will not be able to use .htaccess files, cgi scripts, etc. in your repository directory. For instance, if you setup your repository at http://svn.example.com/, you will not be able to password protect that directory using .htaccess. You must use the Public/Private field in the Subversion panel page. Changes made in the Htaccess/WebDAV panel also do not apply to your SVN repository.

This also means you can't install ViewVC in the main repository directory. To work around this, put your repository in http://svn.example.com/svn/ and the ViewVC cgi in http://svn.example.com/. Remember, you'll need to use a .htaccess file to configure http://svn.example.com/, but the Public/Private field in the Subversion panel to protect http://svn.example.com/svn/.

Hastily-made repositories often don't work: If you create your repository before its intended host is fully created (and resolved), you may have an inaccessible repository. Assuming it doesn't yet contain any information (how could it?), just delete it and recreate it. (Alternatively, you may be experiencing a DNS propagation delay if you can access your repository via http within the DreamHost system, but see an empty directory from outside DreamHost [Apache 1.3x serving your empty domain]. If you can't wait, try querying the DH DNS servers for your IP and using a local hosts file or NetInfo to temporarily resolve your svn host. Remember to undo this when DNS records have propagated.)

Hosting more than one Subversion domain: You can host multiple svn domains and subdomains under one Dreamhost account, but they are not completely independent. In particular, all repositories created with the same FTP account share the same namespace, even if under different URLs. With a single FTP account, a given repository name can only be used once for all svn domains. If you create http://svn1.example.com/repo, you cannot have a second repository named http://svn2.example.com/repo. If you do configure http://svn2.example.com/repo, it will be a second name for the same repository, with a separate set of permissions. If you must create two repositories with the same name, create a second FTP user.

Hosting subversion for a domain that is not on Dreamhost: If you have a domain which is not hosted on Dreamhost and you want to set up Subversion on a subdomain of that domain, it will not work with a normal setup. Instead, you must set up a subdomain to a domain hosted on Dreamhost (e.g., realsvn.exampleOnDreamhost.com), then create a Dreamhost mirror to that domain from the domain you want (e.g., svn.exampleNOTonDreamhost.com). Make sure you wait for DNS propagation to occur before testing everything.

File Ownership Problems: On Dreamhost subversion runs as the dhapache user. If you create a file, it is owned by yourusername, not dhapache and subversion can't read it. It is pretty easy to have this happen. (For example, the backup feature of the popular emacs text editor will do it: to prevent this add (setq backup-by-copying t) to your .emacs file.) Once dhapache has lost ownership of the file, your repository becomes unmodifiable and your users will get "permission denied" errors when they try to commit.

1. Open DreamHost Subversion Control Panel
2. Under "Actions" click "Edit" for the appropriate repository
3. Add a new user and password (any will do...just make the pw non-guessable)
4. Click "Update my repository now!"

In the process of adding a new user, the DreamHost job will recursively change file ownership for the whole repository back to dhapache.

Some have reported success just submitting an edit (with no changes) to their repository in the Control Panel. This operation recreates your reponame.access and reponame.passwd files re-establishing dhapache as their group (and undoing any MD5 passwords you've made manually). Unfortunately, this does nothing to fix your repository if the owner has been changed from dhapache to your username.

If neither of these work, you may have invoke the nuclear option: dump, recreate and reload your repository.

It would be nice if the Subversion Control Panel had an explicit option to fix file owners and groups directly with e.g. a script like this:

sudo chown -R dhapache ~/svn/reponame;
sudo chgrp dhapache ~/svn/reponame.access ~/svn/reponame.passwd;


Another nice feature would be a Control Panel switch to allow passwords to be created and maintained with MD5 encryption.

Some clients require MD5 passwords: If you get "access denied" warnings, you may need to use MD5 passwords instead of the standard variety created by the DreamHost Control Panel. Use htpasswd -nm username to generate the entry (ala username:passwd-hash) for your reponame.passwd file. And use an editor (ala nano reponame.passwd) to replace your standard password entry.

Don't overwrite your reponame.access and reponame.passwd files with echo "username:passwd-hash" > reponame.passwd Overwriting the files will cause them to have your user's group instead of dhapache, leaving your repository in a read-only or inaccessible state.

Removing repositories through the control panel doesn't seem to remove the ~/svn/<repo-id> directory. (as of Apr 12 2006) Workaround:

cd ~/svn;
mkdir old;
mv <repo-id> old


You have the proper permissions to do this. (You can also use WebFTP to delete or rename the repository directory.)

Warning: It has been reported that DreamHost's "Extra Web Security" (Mod_security) can interfere with proper operation of Subversion on DreamHost servers. If you find that you are having trouble with checkouts, and a check of your error.log shows a "ModSecurity:" error, you can resolve this issue by disabling mod_security for your domain ("Edit" the "Web Hosting" setup in the "Domains -> Manage Domains" section of the panel and uncheck the "Extra Web Security" checkbox).

Connecting to Subversion Repository

Using svn+ssh

Allows for a svn client to connect directly with the repository via ssh.

You have to set up a ssh username and password. Subversion users defined in the panel will not be used for authentication.

   svn+ssh://{user}@www.yourdomain.ext/home/{user}/svn/{project}


note: {project} is the ID of your subversion project, NOT the projectname.

Using HTTP

1. Use the HTTP path that you used in the Subversion panel.
Is there any way for svn users to change their password in this mode? No. Only through panel.
Is there any way to use https instead of http? Yes, but first you will need a unique IP address and Secure Server installed on your domain.

Using the Command Line (CLI)

• Locally (assuming your project is hosted on Dreamhost and can be accessed from your shell).
svn list file:///home/{user}/svn/{project}

• HTTP.
svn list {projectURL}

• SSH Tunnel.
svn list svn+ssh://{user}@www.yourdomain.ext/home/{user}/svn/{project}


note: {project} is the ID of your subversion project, NOT the projectname, which can be found on the Subversion panel.
note: {projectURL} is the Project URL chosen by you on the Subversion panel.

How to use: quick reference

 The instructions provided in this article or section require shell access unless otherwise stated. You can use the PuTTY client on Windows, or SSH on UNIX and UNIX-like systems such as Linux or Mac OS X.Your account must be configured for shell access in the Control Panel.More information may be available on the article's talk page.

Creating Repository via Command-Line

If you didn't use the Dreamhost Subversion Panel, you can create the repository at a directory. If you used the Quick Start method then skip this step and go to the next one.

svnadmin create /home/user/path/to/repository


Gotchas

Handmade repos are read-only (via http): If you find that you have to tweak and reload your dumpfile a few times, it can be handy to use the CLI tools (e.g. rm -rf and svnadmin create) to wipe and recreate your repository until you get it right. But then you'll want to use the Control Panel to delete and recreate your repository. Your test repositories will not function properly in production (they won't permit any changes).

The Panel creates the repository with dhapache as the owner, and the reponame.access and reponame.passwd files with dhapache as the group. Trying to create your own production repo with svnadmin create is futile because you don't have authorization to change those ownerships and group memberships (and you're not a sudoer).

Don't overwrite dhapache files: Don't overwrite your reponame.access and reponame.passwd files with echo "username:passwd-hash" > reponame.passwd (e.g. if you're trying to use MD5 passwords). Use an editor and paste in the new data. Overwriting the files will cause them to have your user's group instead of dhapache. If your repository is relatively mature when you make this mistake, and you have no backup, you will be out of options.

Importing Folders and Files

Once the repository is created you can add folders and files that you have in another location. It is better to use this method to keep the revisions number down when first creating the repository.

svn import /home/USER/path/to/source file:///home/USER/path/to/repository --message="Importing Project"


You have to put a message in and change the text inside to whatever you are doing at the time.

Sometimes, you would have an existing repository that you want to migrate to your Dreamhost svn repository. You will need to take a dump of your existing repository and load it into your Dreamhost repository.

 svnadmin dump path-to-repo | gzip > dumpfile.gz

If you set up using the Dreamhost Subversion Panel, then the repository will be under the $HOME/svn/{repo-id} where the repo-id is the id you used to setup the repository in the panel. Decompress the dumpfile first. gunzip -c home_dir/dumpfile.gz | svnadmin load svn/repository_id  Command should show all files being imported, if not then check the instructions and try again. Using TortoiseSVN TortoiseSVN is a Windows GUI integration program for svn. Use at your own risk, it is not officially supported. Using HTTP 1. Download the TortoiseSVN client from the official site 2. Run the installer 3. Create a folder somewhere and leave it empty. Any name and location on your own computer will do. A folder under My documents or on your desktop might be convenient. 4. Open the context menu of the folder (by right clicking on it for example) and you will notice a few new items somewhere halfway the menu, in particular SVN Checkout... and TortoiseSVN which is a submenu. 5. Choose SVN Checkout.... A new window called Checkout wil open. 6. In the Repository section, fill out the URL of your repository. Don't forget to start with http://. For example : http://svn.mysite.com/myrepository/. 7. You can immediately type the full path in your svn that you would like to check out or you can now click the button with the ... besides the URL field. This will let you browse the contents of your repository and choose a specific folder. It might take a minute to load. 1. If you get a 405 error that says something about not having permission, you may have mistyped the URL for your repository and ended up on your regular webserver instead of inside the repository. If you have this problem repeatedly, use a command shell to do the checkout. 2. Note that your repository is completely empty if you just created it. The repository browser allows you to create folders and move them around, but that's about it. 8. The Checkout directory should already be filled in, there are two checkboxes (Only check out the top folder and Omit externals) which you should leave unchecked. If you just plan to have a simple repository you probably won't be needing them at all. Otherwise read about them in the TortoiseSVN help (folder context menu > TortoiseSVN submenu > Help). 1. You may rename the local directory if you wish, but do not give it a name ending in .com (as suggested below for the server), as this can cause problems with some Windows security programs that flag the directory as an executable file. 9. Leave Revision at HEAD revision for now. Go ahead and confirm this dialog with the OK button. You should now see a log screen and after a few seconds it should say complete at revision 0. 10. At this point you can start working in the folder, if you already have a project you were working on just move it all into this folder. 11. Now pull up the folder context menu and choose SVN Commit... 12. This brings up a window where you can choose which files should be included in the SVN. If you're working with software and compiling things a lot of temporary files and binaries get generated that are absolutely not necessary since they can be easily regenerated from the source code. You should uncheck these to avoid needless traffic and storage usage. Congratulations, at this point, you're in business! You can now make changes and commit them, revert if you want to undo (TortoiseSVN submenu) everything after the last commit and much more. The TortoiseSVN help is always available for more details. Note that this method sends everything over the internet in cleartext, which may or may not be much of a problem to you.  Using an SSH tunnel This walkthrough assumes username is myname, with a website at www.mysite.com, and that the repositories are in ~/svn starting with a project named myproject. You can choose your own directory names. Step 1: Create the repository following the Repository section of this guide. Step 2: Download and install SVN client Create Session Key If you don't create the public session key, you will have to type your password in for every action in the browser and for every time TortoiseSVN connects to the server. Start in your home directory cd ~  Generate the key set using the passphrase of your choice and put the public key in a .ssh directory (note: the name "rsakey" isn't required) Write down your passphrase as you will need it later. ssh-keygen -b 1024 -t rsa -N SomeLongTextForPassphrase -f rsakey  Create the .ssh folder mkdir .ssh  Move the public key inside of the folder and rename it. mv rsakey.pub .ssh/authorized_keys  Change permissions on both the folder and file for security. chmod 700 .ssh chmod 600 .ssh/authorized_keys  Download and install the Putty tools (scroll down to the Windows-style installer). This is an SSH client with authentication tools. Download your "rsakey" file (your private key) from the server to your local machine (the rsakey should be in your home directory). Use your Windows FTP client.  Load it into the PuTTYgen tool (puttygen.exe) and enter your passphrase when it asks for it. Use SSH-2 (RSA) which will be the default.  Save it as a private key from PuTTYgen in a safe place as rsakey.ppk. Setup New Session 1. Run PuTTY Pageant. Pageant will put an icon of a computer wearing a hat into the System tray. 2. Load a private key into it. Double click on the icon and then click on Private Key File. 3. Type in the Passphrase. • Run Putty and make a new session: • Hostname: www.mysite.com • Protocol: SSH • Saved Sessions: mysiteSSH • Connection->Data->auto-login username: myuser • Connection->SSH->preferred protocol: 2 • Connection->SSH->Auth->private key file: path\to\rsakey.ppk • Click "Save" on the sessions panel to save this config. • Open PuTTY if you want to test your session. PuTTY will notice that Pageant is running, retrieve the key automatically from Pageant, and use it to authenticate. You can now open as many PuTTY sessions as you like without having to type your passphrase again. You may get a message saying, "The server's host key is not set in the registry." (Insert what this means here.) • Now find your local project directory, and copy what you want to add to Subversion into a temporary directory (let's call it "ImportMe"), organizing it carefully -- it's smart to put your files in a "trunk" directory so that working with new branches and tags later is simple. • Right-click on the ImportMe folder and select "Import..." from the TortoiseSVN submenu. You will be adding everything inside this folder into the root of the "myproject" repository. • In the import dialog, enter the URL of Repository like this. Replace "mysiteSSH" with the name of your PuTTY stored session and "myusername" with your real username. If you just want a straight SSH tunnel, we'd use myuser@www.mysite.com here instead of mysiteSSH: svn+ssh://mysiteSSH/home/myusername/svn/myproject ...and click "Okay". This will load your project files into the repository. • Next, check out the files you want to work with into your project directory (but make sure you aren't overwriting files when you check out or you'll get errors). This is the "SVN Checkout..." option in the folder context menu. Everything should be pretty self-explanatory from there on. Other References Guide from TortoiseSVN site (generate RSA key instead of DSA key). Notes • TortoiseSVN (1.1.3) - Go into Settings and enter TortoisePlink as the SSH client under the Network tab to connect to your repository. You can use svn+ssh://myusername@mysiteSSH/home/myusername/svn/myproject to specify your username directly in the URL. Along with Pageant for key-based authentication, using TortoiseSVN is very transparent and easy to use. Also screen is getting over worked for overnight checkouts (yes overnight) screen svn co &> ~/log_co & ^ad  Multiple User Access to Repository (I have only tried this in a bundy shell, not externally (with TortoiseSVN, for example) • Create at least two users (mysvnadmin, mysvnuser) • Create the repository and import the project with mysvnuser. • Login (ssh) to mysvnuser's account: $ su mysvnuser
$svn co file:///home/mysvnadmin/repos/project work$ svn add file
$svn commit -m "added file"$ svn log
r1 | mysvnadmin | 2005-09-04 08:03:47 -0700 (04 Sep 2005) | 1 line
initial import
r2 | mysvnuser | 2005-09-04 23:34:13 -0700 (04 Oct 2005) | 1 line