Mercurial > treepkg
changeset 303:df01eb4dbfc5
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.
author | Bernhard Herzog <bh@intevation.de> |
---|---|
date | Thu, 26 Nov 2009 15:37:48 +0000 |
parents | 020421cd3ee2 |
children | 6cffb43a28ca |
files | treepkg/subversion.py |
diffstat | 1 files changed, 31 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- 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."