From 975b3f30605c36a714bf5b9619817a897cb6a4a3 Mon Sep 17 00:00:00 2001 From: Sam Thursfield Date: Fri, 24 Aug 2012 17:57:49 +0100 Subject: Support 'git ls-tree' in local and remote repos --- morphlib/cachedrepo.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'morphlib/cachedrepo.py') 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)]) -- cgit v1.2.1