From bec9ecbbb7ab988488c77ea1fe995164ec0c073f Mon Sep 17 00:00:00 2001 From: Sam Thursfield Date: Thu, 13 Dec 2012 14:23:33 +0000 Subject: morph branch: Check if the ref already exists before anything else This was done to ensure tests.branching/branch-fails-if-branch-exists always passes, but also seems like the right approach in general. --- morphlib/cachedrepo.py | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'morphlib/cachedrepo.py') diff --git a/morphlib/cachedrepo.py b/morphlib/cachedrepo.py index 312f580f..0a085bb2 100644 --- a/morphlib/cachedrepo.py +++ b/morphlib/cachedrepo.py @@ -104,6 +104,15 @@ class CachedRepo(object): self.path = path self.is_mirror = not url.startswith('file://') + def ref_exists(self, ref): + '''Returns True if the given ref exists in the repo''' + + try: + self._rev_parse(ref) + except cliapp.AppException: + return False + return True + def resolve_ref(self, ref): '''Attempts to resolve a ref into its SHA1 and tree SHA1. -- cgit v1.2.1