From 63927c35611bf56a1fce03750e953ec5250fb282 Mon Sep 17 00:00:00 2001 From: Jannis Pohlmann Date: Wed, 18 Apr 2012 13:55:32 +0100 Subject: Raise a RepositoryNotFoundError if a repo does not exist in the cache. --- morphcacheserver/repocache.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'morphcacheserver') diff --git a/morphcacheserver/repocache.py b/morphcacheserver/repocache.py index 49b82001..1b6862cb 100644 --- a/morphcacheserver/repocache.py +++ b/morphcacheserver/repocache.py @@ -19,6 +19,13 @@ import os import string +class RepositoryNotFoundError(cliapp.AppException): + + def __init__(self, repo): + cliapp.AppException.__init__( + self, 'Repository %s does not exist in the cache' % repo) + + class InvalidReferenceError(cliapp.AppException): def __init__(self, repo, ref): @@ -44,6 +51,8 @@ class RepoCache(object): def resolve_ref(self, repo_url, ref): quoted_url = self._quote_url(repo_url) repo_dir = os.path.join(self.dirname, quoted_url) + if not os.path.exists(repo_dir): + raise RepositoryNotFoundError(repo_url) try: refs = self._show_ref(repo_dir, ref).split('\n') refs = [x.split() for x in refs if 'origin' in x] @@ -60,9 +69,10 @@ class RepoCache(object): def cat_file(self, repo_url, ref, filename): quoted_url = self._quote_url(repo_url) repo_dir = os.path.join(self.dirname, quoted_url) - if not self._is_valid_sha1(ref): raise UnresolvedNamedReferenceError(repo_url, ref) + if not os.path.exists(repo_dir): + raise RepositoryNotFoundError(repo_url) try: sha1 = self._rev_list(repo_dir, ref).strip() except: -- cgit v1.2.1