summaryrefslogtreecommitdiff
path: root/morphlib/gitdir.py
diff options
context:
space:
mode:
authorPedro Alvarez <pedro.alvarez@codethink.co.uk>2016-03-26 18:59:01 +0000
committerPedro Alvarez <pedro.alvarez@codethink.co.uk>2016-03-26 19:27:19 +0000
commit45e39e81698df91251c7fac5a642e211e98d834b (patch)
treef4d2fa2774dd29f302617002bd8da417928a1408 /morphlib/gitdir.py
parent9404317020ff0455cbfd3ca7976d546af823759b (diff)
downloadmorph-baserock/pedroalvarez/defv8-submodules-squashed.tar.gz
Add support for definitions version 8baserock/pedroalvarez/defv8-submodules-squashed
This code is a rework from changes done by: - Tiago Gomes <tiago.gomes@codethink.co.uk> https://storyboard.baserock.org/#!/story/86 Change-Id: I3475c2bcb648a272fee33bc878a521f79d4e6581
Diffstat (limited to 'morphlib/gitdir.py')
-rw-r--r--morphlib/gitdir.py22
1 files changed, 22 insertions, 0 deletions
diff --git a/morphlib/gitdir.py b/morphlib/gitdir.py
index ca4a4c76..24dd9ed7 100644
--- a/morphlib/gitdir.py
+++ b/morphlib/gitdir.py
@@ -54,6 +54,14 @@ class ExpectedSha1Error(cliapp.AppException):
self, 'SHA1 expected, got %s' % ref)
+class MissingSubmoduleCommitError(cliapp.AppException):
+
+ def __init__(self, repo, ref, submodule):
+ cliapp.AppException.__init__(self, # pragma
+ '%s:%s:.gitmodules: No commit object found for '
+ 'submodule "%s"' % (repo, ref, submodule))
+
+
class RefChangeError(cliapp.AppException):
pass
@@ -822,6 +830,20 @@ class GitDirectory(object):
except Exception as e:
raise RefDeleteError(self, ref, old_sha1, e)
+ def get_submodule_commit(self, parent_ref,
+ submodule_path): # pragma: no cover
+ try:
+ lstree_output = morphlib.git.gitcmd(self._runcmd, 'ls-tree',
+ parent_ref, submodule_path)
+ except cliapp.AppException:
+ raise MissingSubmoduleCommitError(self.dirname, parent_ref,
+ submodule_path)
+ m = re.match("160000 commit (?P<sha1>\w{40})", lstree_output)
+ if not m:
+ raise MissingSubmoduleCommitError(self.dirname, parent_ref,
+ submodule_path)
+ return m.group('sha1')
+
def describe(self):
version = morphlib.git.gitcmd(self._runcmd, 'describe',
'--always', '--dirty=-unreproducible')