[Treepkg-commits] r229 - trunk/treepkg

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Thu Nov 26 16:37:49 CET 2009


Author: bh
Date: 2009-11-26 16:37:48 +0100 (Thu, 26 Nov 2009)
New Revision: 229

Modified:
   trunk/treepkg/subversion.py
Log:
Check the URL of a working copy when updating a track's working copy.
The URL used to originally check out the working must still match the
one given in the configuration file.  If it doesn't match, a
SubversionUrlMismatchError is raised.


Modified: trunk/treepkg/subversion.py
===================================================================
--- trunk/treepkg/subversion.py	2009-11-26 15:23:13 UTC (rev 228)
+++ trunk/treepkg/subversion.py	2009-11-26 15:37:48 UTC (rev 229)
@@ -24,7 +24,11 @@
     """Base class for subversion specific errors raised by TreePKG"""
 
 
+class SubversionUrlMismatchError(SubversionError):
 
+    """The repository URL does not match the URL of a working copy"""
+
+
 def list_url(url):
     """Runs svn list with the given url and returns files listed as a list"""
     output = run.capture_output(cmdexpand("svn list $url", **locals()))
@@ -76,6 +80,18 @@
                               % svn_working_copy)
     return int(str_rev)
 
+def svn_url(url_or_working_copy):
+    """Returns the URL used for the working copy in svn_working_copy"""
+    # Make sure we run svn under the C locale to avoid localized
+    # messages
+    env = os.environ.copy()
+    env["LANG"] = "C"
+
+    output = run.capture_output(cmdexpand("svn info $url_or_working_copy",
+                                          **locals()),
+                                env=env)
+    return extract_value_for_key(output.splitlines(), "URL:")
+
 def log_xml(url, base_revision):
     """Return the log in XML of the repository at url from base_revision to HEAD
     """
@@ -133,7 +149,21 @@
         return max([last_changed_revision(os.path.join(localdir, d))
                     for d in [localdir] + list(self.external_subdirs)])
 
+    def check_working_copy(self, localdir):
+        """Checks whether localdir contains a checkout of the
+        repository.  The check compares the expected URL with the one
+        returned by svn info executed in localdir.  Raises
+        SubversionUrlMismatchError if the URLs do not match.
+        """
+        localurl = svn_url(localdir)
+        expected_url = svn_url(self.url)
+        if localurl != expected_url:
+            raise SubversionUrlMismatchError("Working copy in %r has URL %r,"
+                                             " expected %r"
+                                             % (localdir, localurl,
+                                                expected_url))
 
+
 class SvnWorkingCopy(object):
 
     """Represents a checkout of a subversion repository"""
@@ -159,6 +189,7 @@
         """Updates the working copy or creates by checking out the repository"""
         if os.path.exists(self.localdir):
             self.log_info("Updating the working copy in %r", self.localdir)
+            self.repository.check_working_copy(self.localdir)
             update(self.localdir, revision=revision)
         else:
             self.log_info("The working copy in %r doesn't exist yet."



More information about the Treepkg-commits mailing list