As an initial idea subversion serves to manage a set of files (repository) and its different versions. It is relevant to note that we do not care how the files are saved, but rather how we can access them, for which it is common to use a database. The idea of a repository is like a directory from which we want to recover a file of one week or 10 months ago based on the database status, to recover the latest versions and add new ones. Unlike cvs, subversion makes global revisions of the repository, which means that a change in a file does not generate a leap in version of that file only, but also of the entire repository, which adds one to the revision. In addition to the book we have mentioned (http://svnbook.red-bean.com/nightly/es/index.html), consult the documentation at http://subversion.tigris.org/servlets/ProjectDocumentList.
In Debian, we will have to type apt-get install subversion, if we wish to publish the repositories in Apache2 apt-get install Apache2-common and the specific module apt-get install libApache2-subversion.
First step: create our repository, user (we assume the user is svuser), group (svgroup) as root...
mkdir -p /usr/local/svn addgroup svgroup chown -R root.svgroup /usr/local/svn chmod 2775 /usr/local/svn
addgroup svuser svggroup Adds the svuser user to the svgroup group.
We connect as svuser and verify that we are in the svgroup group (with the group command).
| svnadmin create /usr/local/svn/tests |
| This command will create a series of files and directories for version management and control. If we are not permitted in /usr/local/svn, we can do so in the local directory:mkdir -p $HOME/svndirand nextsvnadmin create $HOME/svndir/tests. |
Next we create a temporary directory mkdir -p $HOME/svntmp/tests we move to the directory cd $HOME/svntmp/tests and create a file like: echo First File Svn 'date' > file1.txt.
We transfer it to the repository: inside the directory we type svn import file:///home/svuser/svndir/tests-m "View. Initial". If we have created it in /usr/local/svn/tests we should type the full path after file://. The import command copies the directory tree and the -m option allows the version message to be shown. If we do not add the -m option, an editor will open to do so (we need to enter a message in order to avoid problems). The subdirectory $HOME/svntmp/tests is a copy of the work in the repository and deleting it is recommended so as not to be tempted to commit the error of working with it and not with the repository (rm -rf $HOME/svntmp/tests).
Once in the repository, we can obtain the local copy where we can work and then upload the copies to the repositories, by typing:
mkdir $HOME/svm-work cd $HOME/svn-work svn checkout file:///home/svuser/svndir/tests
Where we will see that we have the tests directory. We can copy with another name adding the name we want at the end. To add a new file to it:
cd /home/kikov/svn-work/tests echo Second File Svn 'date' > file2.txt svn add file2.txt svn commit -m"New file"
It is important to note that once in the local copy (svn-work) we must not specify the path. svn add marks to add the file to the repository and that really it is added when we run cvn commit. It will give us some messages indicating that it is the second version.
If we add another line file1.txt with echo 'date'>>file1.txt, then we will be able to upload the changes with: svn commit -m"New line".
It is possible to compare the local file with the repository file, for example we add a third line to file1.txt with echo 'date'>>file1.txt, but we do not upload it and if we want to see the differences we can run: svn diff.
This command will highlight what the differences are between the local file and those of the repository. If we load it with svn commit -m"New line2" (which will generate another version) then the svn diff will not give us any differences.
We can also use the command svn update within the directory to update the local copy. If there are two or more users working at the same time and each one has made a local copy of the repository and modifies it (by doing commit), when the second user goes to commit their copy with their modifications, they will receive a conflict error, since the copy in the repository has a more recent modification date than this user's original copy (in other words, there have been changes in between), meaning that if the second user runs commit, we could lose the modifications of the first one. To do this, we must run svn update which will tell us the file that creates a conflict with a C and will show us the files where the parts in conflict have been placed. The user must decide what version to keep and whether they can run commit.
An interesting command is the svn log file1.txt, which will show all the changes that have been made to the file and its corresponding versions.
An interesting feature is that subversion can run in conjunction with Apache2 (and also over SSL) to be accessed from another machine (consult the clients in http://svnbook.red-bean.com/) or simply look at the repository. In Debian Administration they explain how to configure Apache2 and SSL for Sarge, or as we already indicated in the part on servers. For this, we need to activate the WebDAV modules (see http://www.debian-administration.org/articles/285 or in their absence http://www.debian-administration.org/articles/208.
| As root user we type: |
| mkdir /subversión chmod www-data:www-data |
| So that Apache can access the directory |
| svnadmin create /subversion |
| we create the repository |
| ls -s /subversion |
-rw-r--r-- 1 www-data www-data 376 May 11 20:27 README.txt drwxr-xr-x 2 www-data www-data 4096 May 11 20:27 conf drwxr-xr-x 2 www-data www-data 4096 May 11 20:27 dav drwxr-xr-x 2 www-data www-data 4096 May 11 20:28 db -rw-r--r-- 1 www-data www-data 2 May 11 20:27 format drwxr-xr-x 2 www-data www-data 4096 May 11 20:27 hooks drwxr-xr-x 2 www-data www-data 4096 May 11 20:27 locks
For authentication we use htpasswd (for example with htpasswd2 -c -m /subversion/.dav_svn.passwd user created as www-data. We only have to type the -c the first time that we execute the command to create the file. This tells us that in order to access this directory we need a password (which is the one we have entered for user).
Then we will need to change the httpd.conf so that it is something like:
<location /svn> DAV svn SVNPath /subversion AuthType Basic AuthName "Subversion Repository" AuthUserFile /subversion/.dav_svn.passwd Require valid-user </location>
We reinitiate Apache and now we are ready to import some files, such as:
svn import file1.txt http://url-server.org/svn \ -m "Import Initial"
We will be asked for authentication (user/password) and told that the file file1.txt has been added to the repository.