let subversion export support auth and revision

This commit is contained in:
Qiangning Hong 2012-01-31 18:56:47 +08:00
parent 5df6c3aede
commit 363cc60154
2 changed files with 29 additions and 12 deletions

View File

@ -57,6 +57,7 @@ class Subversion(VersionControl):
def export(self, location):
"""Export the svn repository at the url to the destination location"""
url, rev = self.get_url_rev()
rev_options = get_rev_options(url, rev)
logger.notify('Exporting svn repository %s to %s' % (url, location))
logger.indent += 2
try:
@ -65,7 +66,7 @@ class Subversion(VersionControl):
# --force fixes this, but was only added in svn 1.5
rmtree(location)
call_subprocess(
[self.cmd, 'export', url, location],
[self.cmd, 'export'] + rev_options + [url, location],
filter_stdout=self._filter, show_stdout=False)
finally:
logger.indent -= 2
@ -80,17 +81,11 @@ class Subversion(VersionControl):
def obtain(self, dest):
url, rev = self.get_url_rev()
rev_options = get_rev_options(url, rev)
if rev:
rev_options = ['-r', rev]
rev_display = ' (to revision %s)' % rev
else:
rev_options = []
rev_display = ''
r = urlsplit(url)
if r.username:
rev_options += ['--username', r.username]
if r.password:
rev_options += ['--password', r.password]
if self.check_destination(dest, url, rev_options, rev_display):
logger.notify('Checking out %s%s to %s'
% (url, rev_display, display_path(dest)))
@ -245,4 +240,18 @@ class Subversion(VersionControl):
full_egg_name = '%s-dev_r%s' % (egg_project_name, rev)
return 'svn+%s@%s#egg=%s' % (repo, rev, full_egg_name)
def get_rev_options(url, rev):
if rev:
rev_options = ['-r', rev]
else:
rev_options = []
r = urlsplit(url)
if r.username:
rev_options += ['--username', r.username]
if r.password:
rev_options += ['--password', r.password]
return rev_options
vcs.register(Subversion)

View File

@ -3,11 +3,19 @@ from pip.vcs.subversion import Subversion
from tests.test_pip import reset_env
@patch('pip.vcs.subversion.call_subprocess')
def test_svn_should_recognize_auth_info_in_url(call_subprocess_mock):
def test_obtain_should_recognize_auth_info_in_url(call_subprocess_mock):
env = reset_env()
svn = Subversion(url='svn+http://username:password@svn.example.com/')
svn.obtain(env.scratch_path/'test')
call_subprocess_mock.assert_called_with([
svn.cmd, 'checkout', '-q', '--username', 'username', '--password',
'password', 'http://username:password@svn.example.com/',
env.scratch_path/'test'])
svn.cmd, 'checkout', '-q', '--username', 'username', '--password', 'password',
'http://username:password@svn.example.com/', env.scratch_path/'test'])
@patch('pip.vcs.subversion.call_subprocess')
def test_export_should_recognize_auth_info_in_url(call_subprocess_mock):
env = reset_env()
svn = Subversion(url='svn+http://username:password@svn.example.com/')
svn.export(env.scratch_path/'test')
assert call_subprocess_mock.call_args[0] == ([
svn.cmd, 'export', '--username', 'username', '--password', 'password',
'http://username:password@svn.example.com/', env.scratch_path/'test'],)