summaryrefslogtreecommitdiff
path: root/morphlib/cachedrepo.py
diff options
context:
space:
mode:
authorSam Thursfield <sam.thursfield@codethink.co.uk>2012-08-24 17:57:49 +0100
committerSam Thursfield <sam.thursfield@codethink.co.uk>2012-08-24 17:57:49 +0100
commit975b3f30605c36a714bf5b9619817a897cb6a4a3 (patch)
tree5564243efa6a55dc49ed05c2455e70b32598c6bf /morphlib/cachedrepo.py
parent6c13c2ebdea1da19bf359fef9a9e0b08e5491a4a (diff)
downloadmorph-975b3f30605c36a714bf5b9619817a897cb6a4a3.tar.gz
Support 'git ls-tree' in local and remote repos
Diffstat (limited to 'morphlib/cachedrepo.py')
-rw-r--r--morphlib/cachedrepo.py22
1 files changed, 22 insertions, 0 deletions
diff --git a/morphlib/cachedrepo.py b/morphlib/cachedrepo.py
index d7f22400..f647102f 100644
--- a/morphlib/cachedrepo.py
+++ b/morphlib/cachedrepo.py
@@ -158,6 +158,24 @@ class CachedRepo(object):
except cliapp.AppException:
raise CheckoutError(self, ref, target_dir)
+ def ls_tree(self, ref):
+ '''Return file names found in root tree. Does not recurse to subtrees.
+
+ Raises an UnresolvedNamedReferenceError if the ref is not a SHA1
+ ref. Raises an InvalidReferenceError if the SHA1 ref is not found
+ in the repository.
+
+ '''
+
+ if not self.is_valid_sha1(ref):
+ raise UnresolvedNamedReferenceError(self, ref)
+ try:
+ sha1 = self._rev_list(ref).strip()
+ except cliapp.AppException:
+ raise InvalidReferenceError(self, ref)
+
+ return self._ls_tree(sha1)
+
def update(self):
'''Updates the cached repository using its origin remote.
@@ -182,6 +200,10 @@ class CachedRepo(object):
def _rev_list(self, ref): # pragma: no cover
return self._runcmd(['git', 'rev-list', '--no-walk', ref])
+ def _ls_tree(self, ref): # pragma: no cover
+ result = self._runcmd(['git', 'ls-tree', '--name-only', ref])
+ return result.split('\n')
+
def _cat_file(self, ref, filename): # pragma: no cover
return self._runcmd(['git', 'cat-file', 'blob',
'%s:%s' % (ref, filename)])