# HG changeset patch # User Bernhard Herzog # Date 1259249868 0 # Node ID df01eb4dbfc566d74d37b6b18290a73ffc2046c4 # Parent 020421cd3ee2fdb4df444228bd11b91df085359f 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. diff -r 020421cd3ee2 -r df01eb4dbfc5 treepkg/subversion.py --- a/treepkg/subversion.py Thu Nov 26 15:23:13 2009 +0000 +++ b/treepkg/subversion.py Thu Nov 26 15:37:48 2009 +0000 @@ -24,6 +24,10 @@ """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""" @@ -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,6 +149,20 @@ 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): @@ -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."