summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--morphlib/cachedrepo.py27
-rw-r--r--morphlib/cachedrepo_tests.py22
2 files changed, 28 insertions, 21 deletions
diff --git a/morphlib/cachedrepo.py b/morphlib/cachedrepo.py
index eef49ffb..ad17785a 100644
--- a/morphlib/cachedrepo.py
+++ b/morphlib/cachedrepo.py
@@ -44,12 +44,20 @@ class CheckoutDirectoryExistsError(cliapp.AppException):
(target_dir, repo))
+class CloneError(cliapp.AppException):
+
+ def __init__(self, repo, target_dir):
+ cliapp.AppException.__init__(
+ self,
+ 'Failed to copy %s into %s' % (repo.original_name, target_dir))
+
+
class CheckoutError(cliapp.AppException):
def __init__(self, repo, ref, target_dir):
cliapp.AppException.__init__(
self,
- 'Failed to check out %s:%s into %s' % (repo, ref, target_dir))
+ 'Failed to check out ref %s in %s' % (ref, target_dir))
class UpdateError(cliapp.AppException):
@@ -154,11 +162,8 @@ class CachedRepo(object):
os.mkdir(target_dir)
- try:
- self._copy_repository(self.path, target_dir)
- self._checkout_ref(ref, target_dir)
- except cliapp.AppException:
- raise CheckoutError(self, ref, target_dir)
+ self._copy_repository(self.path, target_dir)
+ self._checkout_ref(ref, target_dir)
def ls_tree(self, ref):
'''Return file names found in root tree. Does not recurse to subtrees.
@@ -215,10 +220,16 @@ class CachedRepo(object):
'%s:%s' % (ref, filename)])
def _copy_repository(self, source_dir, target_dir): # pragma: no cover
- morphlib.git.copy_repository(self._runcmd, source_dir, target_dir)
+ try:
+ morphlib.git.copy_repository(self._runcmd, source_dir, target_dir)
+ except cliapp.AppException:
+ raise CloneError(self, target_dir)
def _checkout_ref(self, ref, target_dir): # pragma: no cover
- morphlib.git.checkout_ref(self._runcmd, target_dir, ref)
+ try:
+ morphlib.git.checkout_ref(self._runcmd, target_dir, ref)
+ except cliapp.AppException:
+ raise CheckoutError(self, ref, target_dir)
def _update(self): # pragma: no cover
self._runcmd(['git', 'remote', 'update', 'origin'])
diff --git a/morphlib/cachedrepo_tests.py b/morphlib/cachedrepo_tests.py
index 14c5daac..7c6781c6 100644
--- a/morphlib/cachedrepo_tests.py
+++ b/morphlib/cachedrepo_tests.py
@@ -80,14 +80,10 @@ class CachedRepoTests(unittest.TestCase):
pass
def checkout_ref(self, ref, target_dir):
- bad_refs = [
- 'a4da32f5a81c8bc6d660404724cedc3bc0914a75',
- '079bbfd447c8534e464ce5d40b80114c2022ebf4',
- ]
- if ref in bad_refs:
- # simulate a git failure or something similar to
- # trigger a CheckoutError
- raise cliapp.AppException('git checkout %s' % ref)
+ if ref == 'a4da32f5a81c8bc6d660404724cedc3bc0914a75':
+ raise morphlib.cachedrepo.CloneError(self.repo, target_dir)
+ elif ref == '079bbfd447c8534e464ce5d40b80114c2022ebf4':
+ raise morphlib.cachedrepo.CheckoutError(self.repo, ref, target_dir)
else:
with open(os.path.join(target_dir, 'foo.morph'), 'w') as f:
f.write('contents of foo.morph')
@@ -186,6 +182,11 @@ class CachedRepoTests(unittest.TestCase):
'e28a23812eadf2fce6583b8819b9c5dbd36b9fb9',
self.tempdir.dirname)
+ def test_fail_checkout_due_to_clone_error(self):
+ self.assertRaises(cachedrepo.CloneError, self.repo.checkout,
+ 'a4da32f5a81c8bc6d660404724cedc3bc0914a75',
+ self.tempdir.join('failed-checkout'))
+
def test_fail_checkout_from_invalid_ref(self):
self.assertRaises(cachedrepo.CheckoutError, self.repo.checkout,
'079bbfd447c8534e464ce5d40b80114c2022ebf4',
@@ -200,11 +201,6 @@ class CachedRepoTests(unittest.TestCase):
morph_filename = os.path.join(unpack_dir, 'foo.morph')
self.assertTrue(os.path.exists(morph_filename))
- def test_fail_checkout_due_to_copy_or_checkout_problem(self):
- self.assertRaises(cachedrepo.CheckoutError, self.repo.checkout,
- 'a4da32f5a81c8bc6d660404724cedc3bc0914a75',
- self.tempdir.join('failed-checkout'))
-
def test_ls_tree_in_existing_ref(self):
data = self.repo.ls_tree('e28a23812eadf2fce6583b8819b9c5dbd36b9fb9')
self.assertEqual(data, ['foo.morph'])