Friday, July 24, 2009

Changing SSH username for svn+ssh SVN access method


Having setup SVN over SSH for work purposes one frustration I faced was the issue of switching users for a repository to test path based access control. First I checked out the working copy using a read-only user via:

$>svn co svn+ssh://readonlyuser@myserver/repository/myrepo

Tried to commit a change and it was not allowed as expected. Now to test the read/write user without deleting and rechecking out with the new user. The "readonlyuser" has been cached in the checked out repository. How do I change to a different user?

It took me a long while to figure this out as the following methods do not work. Do the initial checkout by specifying the --username option and hope that we can commit with a different username later:

$>svn co --username readonlyuser svn+ssh://myserver/repository/myrepo

$>svn ci --username readwriteuser

This fails as the --username option is ignored when using the svn+ssh method and the current logged in user account on the client machine will be used as the svn user instead.

Next try using the svn switch command after checking out:

$>svn co svn+ssh://readonlyuser@myserver/repository/myrepo

$>svn switch svn+ssh://readwriteuser@myserver/repository/myrepo

This fails miserably as well with the useless error message:

svn: 'svn+ssh://readonlyuser@myserver/repository/myrepo'
is not the same repository as
'svn+ssh://readwriteuser@myserver/repository/myrepo'

Finally the way that actually works is to use the --relocate option with switch:

$>svn switch --relocate svn+ssh://readonlyuser@myserver/repository/myrepo svn+ssh://readwriteuser@myserver/repository/myrepo

This prompts for the password of the write user and switches the user successfully.

No comments: