summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <lars.wirzenius@codethink.co.uk>2013-10-23 16:21:42 +0000
committerLars Wirzenius <lars.wirzenius@codethink.co.uk>2013-10-24 15:16:40 +0000
commitbcb725108c291611d125f8c5048a368dd5cdadb4 (patch)
tree4dc5a115c4c8bd8106299c0fe46bff4212075812
parent469459ac1a4cd3bd7b5161fe8d71567190257b56 (diff)
downloadmorph-bcb725108c291611d125f8c5048a368dd5cdadb4.tar.gz
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.
-rw-r--r--morphlib/cachedrepo.py13
1 files 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])