From bcb725108c291611d125f8c5048a368dd5cdadb4 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Wed, 23 Oct 2013 16:21:42 +0000 Subject: Make CachedRepo.resolve_ref handle non-existent SHA1 This changes how CachedRepo runs git to get the SHA1 information it needs, based on a suggestion by Richard Maw. --- morphlib/cachedrepo.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 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]) -- cgit v1.2.1