diff options
author | Lars Wirzenius <lars.wirzenius@codethink.co.uk> | 2013-10-24 17:20:47 +0000 |
---|---|---|
committer | Lars Wirzenius <lars.wirzenius@codethink.co.uk> | 2013-10-24 17:20:47 +0000 |
commit | d485c7ee4a6e27efedc7b88172f8af843fd6e2d7 (patch) | |
tree | 4b9949305a67c6565694fd55cb15abdc8b37e670 | |
parent | 53e83cc89dce3434b7b62505ae5a1e359b124267 (diff) | |
parent | 24e0e1ff64b1bcaede0366f9c0765bc740754da8 (diff) | |
download | morph-d485c7ee4a6e27efedc7b88172f8af843fd6e2d7.tar.gz |
Merge remote-tracking branch 'origin/liw/cachedrepo-unit-test-fix-v2-rebase'
Reviewed-by: Richard Maw
-rw-r--r-- | morphlib/cachedrepo.py | 13 | ||||
-rw-r--r-- | morphlib/cachedrepo_tests.py | 5 | ||||
-rw-r--r-- | morphlib/util.py | 6 |
3 files changed, 17 insertions, 7 deletions
diff --git a/morphlib/cachedrepo.py b/morphlib/cachedrepo.py index 0a085bb2..e85b0059 100644 --- a/morphlib/cachedrepo.py +++ b/morphlib/cachedrepo.py @@ -1,4 +1,4 @@ -# Copyright (C) 2012 Codethink Limited +# Copyright (C) 2012-2013 Codethink Limited # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -126,7 +126,11 @@ class CachedRepo(object): except cliapp.AppException: raise InvalidReferenceError(self, ref) - tree = self._show_tree_hash(absref) + try: + tree = self._show_tree_hash(absref) + except cliapp.AppException: + raise InvalidReferenceError(self, ref) + return absref, tree def cat(self, ref, filename): @@ -239,11 +243,12 @@ class CachedRepo(object): return self.app.runcmd(*args, **kwargs) def _rev_parse(self, ref): # pragma: no cover - return self._runcmd(['git', 'rev-parse', '--verify', ref])[0:40] + return self._runcmd( + ['git', 'rev-parse', '--verify', '%s^{commit}' % ref])[0:40] def _show_tree_hash(self, absref): # pragma: no cover return self._runcmd( - ['git', 'log', '-1', '--format=format:%T', absref]).strip() + ['git', 'rev-parse', '--verify', '%s^{tree}' % absref]).strip() def _ls_tree(self, ref): # pragma: no cover result = self._runcmd(['git', 'ls-tree', '--name-only', ref]) diff --git a/morphlib/cachedrepo_tests.py b/morphlib/cachedrepo_tests.py index 18704f58..b1825eba 100644 --- a/morphlib/cachedrepo_tests.py +++ b/morphlib/cachedrepo_tests.py @@ -32,8 +32,11 @@ class CachedRepoTests(unittest.TestCase): "kind": "chunk" }''' + bad_sha1_known_to_rev_parse = 'cafecafecafecafecafecafecafecafecafecafe' + def rev_parse(self, ref): output = { + self.bad_sha1_known_to_rev_parse: self.bad_sha1_known_to_rev_parse, 'a4da32f5a81c8bc6d660404724cedc3bc0914a75': 'a4da32f5a81c8bc6d660404724cedc3bc0914a75', 'e28a23812eadf2fce6583b8819b9c5dbd36b9fb9': @@ -159,7 +162,7 @@ class CachedRepoTests(unittest.TestCase): def test_fail_resolving_an_invalid_sha1_ref(self): self.assertRaises(cachedrepo.InvalidReferenceError, self.repo.resolve_ref, - '079bbfd447c8534e464ce5d40b80114c2022ebf4') + self.bad_sha1_known_to_rev_parse) def test_cat_existing_file_in_existing_ref(self): data = self.repo.cat('e28a23812eadf2fce6583b8819b9c5dbd36b9fb9', diff --git a/morphlib/util.py b/morphlib/util.py index 3d9232d4..53a9e283 100644 --- a/morphlib/util.py +++ b/morphlib/util.py @@ -177,7 +177,8 @@ def log_dict_diff(app, cur, pre): # pragma: no cover dictB = pre for key in dictA.keys(): if key not in dictB: - app.status(msg="New environment: %s = %s" % (key, dictA[key]), + app.status(msg="New environment: %(key)s = %(value)s", + key=key, value=dictA[key], chatty=True) elif dictA[key] != dictB[key]: app.status(msg= \ @@ -185,7 +186,8 @@ def log_dict_diff(app, cur, pre): # pragma: no cover % {"key": key, "valA": dictA[key], "valB": dictB[key]}) for key in dictB.keys(): if key not in dictA: - app.status(msg="Environment removed: %s = %s" % (key, dictB[key])) + app.status(msg="Environment removed: %(key)s = %(value)s", + key=key, value=dictB[key]) # This acquired from rdiff-backup which is GPLv2+ and a patch from 2011 |