How to ignore files and directories in SVN

It is easy to ignore files and directories in Git or Mercurial. Ignore files can be maintained at both the user and repository levels. Git or Mercurial automatically ignore the files and directories that match the patterns listed in these ignore files.

Being a version control system from an older era, Subversion does not have this simple method of ignore.

  • In SVN, ignoring a file or directory is a property that can be set at a specific directory in a repository.

For example, to ignore build subdirectory and *.tmp files:

$ svn propset svn:ignore build .
$ svn propset svn:ignore *.tmp .

Note that both these commands set ignore properties for the current directory .

  • To set an ignore property recursively to all subdirectories in a repository, go to the repository root directory and issue this:
$ svn propset svn:ignore -R *.tmp .
  • Thankfully, you can use an ignore file containing ignore patterns, one per line, as input:
$ svn propset svn:ignore -R -F ~/.svnignore .

Note the difference with Git or Mercurial. You have to manually set this ignore property on every directory. The ignore file we created is for our convenience. If you create a new subdirectory anywhere in this repository, the property needs to be applied again on it.

  • Remember to commit after setting the ignore property.

Tried with: Subversion 1.8.8 and Ubuntu 14.04

Advertisements

SVN info

svn info is the Subversion command to get information about a working copy and the server repository it is checked out from. This can be useful if you have forgotten how you got this working copy or what username was used to do that.

Here is what I get with my SVN:

$ cd
$ cd foobar/src
$ svn info
Path: .
Working Copy Root Path: /home/joe/foobar
URL: svn://svn.bigcorp.com/svn/foobar/src
Relative URL: ^/src
Repository Root: svn://svn.bigcorp.com/svn/foobar
Repository UUID: 601fc6f8-eb90-12e3-bfce-23534615057b
Revision: 24
Node Kind: directory
Schedule: normal
Last Changed Author: joe
Last Changed Rev: 24
Last Changed Date: 2014-08-01 14:07:14 +0800 (Fri, 01 Aug 2014)

Tried with: Subversion 1.8.8 and Ubuntu 14.04

How to checkout subdirectory from Subversion repository

Performing checkout on a Subversion repository is easy. However, if a SVN repository is large in size, you might want to checkout a specific subdirectory to work only on the files inside that. This can also be done in SVN.

For example, assume you have a huge repository named foobar and want to checkout only the subdirectory src/joe from it. This can be done as follows:

$ svn checkout --non-recursive http://svnserver/foobar
$ cd foobar
$ svn update src/joe

Tried with: Subversion 1.8.8 and Ubuntu 14.04

How to use GUI diff with SVN

A GUI diff program can be used for viewing the diff in Subversion by using the --diff-cmd option. For example, to use the Meld GUI diff tool:

$ svn diff --diff-cmd meld

If you find yourself using the GUI diff frequently, consider adding an alias command to your shell that uses this option. For example, if you use the Fish shell, you can add this function:

function svnvdiff --description="SVN diff using GUI diff tool"
    svn diff --diff-cmd meld $argv
end

Tried with: Subversion 1.8.8 and Ubuntu 14.04

How to install and use RabbitVCS

TortoiseSVN is a popular extension to Windows File Explorer that is used to work with Subversion repositories and working copies. The closest alternative to TortoiseSVN in Linux is RabbitVCS. It is pretty easy to install and use it on Ubuntu:

  • Ubuntu might ship with RabbitVCS packages in its repositories, but I have not found them to work correctly! Instead, use the PPA repository ppa:rabbitvcs/ppa:
$ sudo add-apt-repository ppa:rabbitvcs/ppa
$ sudo apt-get update
  • Install the RabbitVCS extension to your Nautilus:
$ sudo apt-get install rabbitvcs-nautilus3
  • Kill and restart Nautilus.

  • Directories that hold SVN repositories should now have icon overlays on them in Nautilus. Right-click on any working copy and use the RabbitVCS SVN option to perform all the usual SVN operations on it. The GUI is similar to that in TortoiseSVN.

Tried with: RabbitVCS 0.15.3, Nautilus 3.4.2 and Ubuntu 12.04 LTS

Side-by-side color diff at terminal using CDiff

20150708_cdiff

If you use Mercurial, Git or Subversion at the shell, CDiff is a useful tool to have around. By default, hg diff or git diff is displayed in the classic diff format. This shows the before-and-after changed lines one below the other. Personally, I find this very confusing. I very much prefer the side-by-side diff view used in GUI diff programs. cdiff is a great way to get this side-by-side diff view at the shell in full color!

Install

CDiff is a Python program that can be installed from PyPI using this command:

$ sudo pip install cdiff

Note: Do not confuse this package with the colordiff package that is available in Ubuntu repositories. That is something else!

Usage

  • Invoke cdiff in any subdirectory of a Mercurial, Git or Subversion repository. By default, this shows a colorful diff of the changes in all uncommitted files.

  • To get side-by-side diff view use: cdiff -s

  • CDiff assumes that your window width is 80 by default. I prefer to view side-by-side diff that uses the full width of my terminal window. This can be achieved by invoking: cdiff -s -w 0

  • To diff two files, just pass them through diff -u and pipe that to cdiff:

$ diff -u file1.cpp file2.cpp | cdiff -s

Tried with: CDiff 0.9.7, Python 2.7.6 and Ubuntu 14.04

How to explore a local Subversion repository in Ubuntu

TortoiseSVN on Windows has a simple and effective explorer that can be used to view the projects and their organization inside a local Subversion repository. There is no TortoiseSVN for Ubuntu.

Instead, the RapidSVN tool nicely fills these shoes. It can be installed easily using the package name rapidsvn.

To explore a local SVN repository, open RapidSVN, right-click on Bookmarks and choose Add Existing Repository. Copy the full path to the directory which holds your local SVN repository. Prefix it with file:// and use that as the URL for RapidSVN. It should now show all the projects and their internal organization.

Tried with: RapidSVN 0.12.0 and Ubuntu 12.04 LTS

TortoiseSVN: Right-Click Context Menus Not Available

Problem: You install TortoiseSVN and find that the right-click context menus and icon overlays are not available!

Solution: Check if you have installed 32-bit TortoiseSVN on 64-bit Windows 7. If yes, uninstall it and install the 64-bit TortoiseSVN.

Explanation:

TortoiseSVN installs itself as an extension to Windows Explorer. The 64-bit Windows Explorer on a 64-bit Windows 7 installation cannot load or communicate with 32-bit TortoiseSVN to display context menus relative to the selected files and directories.

Mercurial: Import Subversion Project

Mercurial is a distributed VCS (DVCS). If you are planning to migrate from Subversion to Mercurial, it might be better to do this on a per-project basis. Due to the nature of a DVCS, it is better to spin off each of your Subversion projects in the repository as separate Mercurial repositories. Here is how:

  1. If you have not already done so, make a copy of the Mercurial configuration file (Mercurial.ini) and add your username. See this post on how to do this.
  2. The command to convert repositories is hg convert. It will not work unless the convert extension is enabled. To do this, open your Mercurial.ini and in the [extensions] section uncomment the convert = line. It should read:
    [extensions]
    convert =
    
  3. The default Windows binaries of Mercurial cannot import from Subversion. If you attempt a hg convert using this binary, you will see an error:
    $ hg convert file:///C:/SVNRep/FoobarProject
    Subversion python bindings could not be loaded
    

    You will need the Python bindings of Subversion and Mercurial installed on top of a standalone Python to be able to do this. That is too messy! But, there is an easier alternative to this. Install TortoiseHg, the Explorer extension to Hg. Its hg.exe has been built with all the necessary bindings. Issue the convert command using its hg.exe:

    $ "C:\Program Files\TortoiseHg\hg.exe" convert file:///C:/SVNRep/FoobarProject
    
  4. This should work. If your Subversion project has been cleanly maintained with the canonical trunks, branches and tags structure hg convert can import all of that correctly into the Mercurial structure of tags.

Subversion: Remove a Project

There is no straightforward way to remove all the information of a project from the SVN repository and retrieve that diskspace. The only way to achieve this:

  1. Dump the repository to a dumpfile.
    $ svnadmin dump C:\Foo_Rep > C:\foo_rep_dump
  2. Filter out the project you want to remove from the dumpfile.
    $ svndumpfilter exclude Project_to_del < C:\foo_rep_dump > C:\foo_rep_dump_updated

    If you have many projects that you want to remove, repeat this step for each of them.

  3. Create a new repository.
    $ svnadmin create C:\Foo_rep_new
  4. Load the updated dumpfile to new repository.
    $ svnadmin load C:\Foo_rep_new < C:\foo_rep_dump_updated