summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarl Meyer <carl@dirtcircle.com>2009-10-03 21:37:23 -0400
committerCarl Meyer <carl@dirtcircle.com>2009-10-03 21:37:23 -0400
commita1ffdfbaac54f2ed9bf597fb5fcc9da22d2df6b7 (patch)
treed273576f363c76d44acca95d2cd97f4eb25bc63a
parent3fce15540ce2ceb5bd4eb61b89955505cfac2fee (diff)
downloadpip-a1ffdfbaac54f2ed9bf597fb5fcc9da22d2df6b7.tar.gz
fix comparison of repo URLs
-rw-r--r--docs/news.txt4
-rw-r--r--pip.py20
-rw-r--r--tests/test_basic.txt13
3 files changed, 32 insertions, 5 deletions
diff --git a/docs/news.txt b/docs/news.txt
index 8f9a0f3ee..452f4e534 100644
--- a/docs/news.txt
+++ b/docs/news.txt
@@ -43,6 +43,10 @@ tip
* Editable freeze URLs now always use revision hash/id rather than tip or
branch names which could move.
+* Fixed comparison of repo URLs so incidental differences such as
+ presence/absence of final slashes or quoted/unquoted special
+ characters don't trigger "ignore/switch/wipe/backup" choice.
+
0.4
---
diff --git a/pip.py b/pip.py
index 52ffc8e57..e73ec2d33 100644
--- a/pip.py
+++ b/pip.py
@@ -2711,6 +2711,18 @@ class VersionControl(object):
assert not location.rstrip('/').endswith(self.dirname), 'Bad directory: %s' % location
return self.get_url(location), self.get_revision(location)
+ def normalize_url(self, url):
+ """
+ Normalize a URL for comparison by unquoting it and removing any trailing slash.
+ """
+ return urllib.unquote(url).rstrip('/')
+
+ def compare_urls(self, url1, url2):
+ """
+ Compare two repo URLs for identity, ignoring incidental differences.
+ """
+ return (self.normalize_url(url1) == self.normalize_url(url2))
+
def parse_vcs_bundle_file(self, content):
"""
Takes the contents of the bundled text file that explains how to revert
@@ -2819,7 +2831,7 @@ class Subversion(VersionControl):
if os.path.exists(os.path.join(dest, self.dirname)):
existing_url = self.get_info(dest)[0]
checkout = False
- if existing_url == url:
+ if self.compare_urls(existing_url, url):
logger.info('Checkout in %s exists, and has correct URL (%s)'
% (display_path(dest), url))
logger.notify('Updating checkout %s%s'
@@ -3089,7 +3101,7 @@ class Git(VersionControl):
existing_url = self.get_url(dest)
rev_options = self.check_rev_options(rev, dest, rev_options)
clone = False
- if existing_url == url:
+ if self.compare_urls(existing_url, url):
logger.info('Clone in %s exists, and has correct URL (%s)'
% (display_path(dest), url))
logger.notify('Updating clone %s%s'
@@ -3266,7 +3278,7 @@ class Mercurial(VersionControl):
if os.path.exists(os.path.join(dest, '.hg')):
existing_url = self.get_url(dest)
clone = False
- if existing_url == url:
+ if self.compare_urls(existing_url, url):
logger.info('Clone in %s exists, and has correct URL (%s)'
% (display_path(dest), url))
logger.notify('Updating clone %s%s'
@@ -3444,7 +3456,7 @@ class Bazaar(VersionControl):
if os.path.exists(os.path.join(dest, '.bzr')):
existing_url = self.get_url(dest)
branch = False
- if existing_url == url:
+ if self.compare_urls(existing_url, url):
logger.info('Checkout in %s exists, and has correct URL (%s)'
% (display_path(dest), url))
logger.notify('Updating branch %s%s'
diff --git a/tests/test_basic.txt b/tests/test_basic.txt
index 6d81d5310..c05bb49e8 100644
--- a/tests/test_basic.txt
+++ b/tests/test_basic.txt
@@ -64,10 +64,15 @@ Cloning from Mercurial::
>>> assert 'src/django-registration' in result.files_created
>>> assert 'src/django-registration/.hg' in result.files_created
+Presence or absence of final slash is also normalized::
+
+ >>> result = run_pip('install', '-e', 'hg+http://bitbucket.org/ubernostrum/django-registration#egg=django-registration', expect_error=True)
+ >>> assert 'pip-log.txt' not in result.files_created, result.files_created['pip-log.txt'].bytes
+
Checking out from Bazaar::
>>> reset_env()
- >>> result = run_pip('install', '-e', 'bzr+http://bazaar.launchpad.net/%7Ejezdez/pip-test/test/#egg=pip-test', expect_error=True)
+ >>> result = run_pip('install', '-e', 'bzr+http://bazaar.launchpad.net/%7Ejezdez/pip-test/test/@1#egg=pip-test', expect_error=True)
>>> egg_link = result.files_created[lib_py + 'site-packages/pip-test.egg-link']
>>> # FIXME: I don't understand why there's a trailing . here:
>>> egg_link.bytes
@@ -75,3 +80,9 @@ Checking out from Bazaar::
>>> assert (lib_py + 'site-packages/easy-install.pth') in result.files_updated
>>> assert 'src/pip-test' in result.files_created
>>> assert 'src/pip-test/.bzr' in result.files_created
+
+Urlquoted characters are normalized for repo URL comparison::
+
+ >>> result = run_pip('install', '-e', 'bzr+http://bazaar.launchpad.net/~jezdez/pip-test/test#egg=pip-test', expect_error=True)
+ >>> assert 'pip-log.txt' not in result.files_created, result.files_created['pip-log.txt'].bytes
+