From 77d75eb06fa07c64b7e14c376fb6e3742ef33fb3 Mon Sep 17 00:00:00 2001 From: Richard Maw Date: Mon, 11 Nov 2013 18:01:47 +0000 Subject: GitDir: Add GitDirectory.commit_tree() method This is used to create commit objects. This is used by build without commit to provide the behind-the-scenes history. --- morphlib/gitdir.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'morphlib/gitdir.py') diff --git a/morphlib/gitdir.py b/morphlib/gitdir.py index 9020506a..aad507a6 100644 --- a/morphlib/gitdir.py +++ b/morphlib/gitdir.py @@ -17,6 +17,7 @@ import cliapp +import itertools import os import morphlib @@ -242,6 +243,25 @@ class GitDirectory(object): return self._runcmd(['git', 'hash-object', '-t', 'blob', '-w', '--stdin'], **kwargs).strip() + def commit_tree(self, tree, parent, message, **kwargs): + '''Create a commit''' + # NOTE: Will need extension for 0 or N parents. + env = {} + for who, info in itertools.product(('committer', 'author'), + ('name', 'email')): + argname = '%s_%s' % (who, info) + envname = 'GIT_%s_%s' % (who.upper(), info.upper()) + if argname in kwargs: + env[envname] = kwargs[argname] + for who in ('committer', 'author'): + argname = '%s_date' % who + envname = 'GIT_%s_DATE' % who.upper() + if argname in kwargs: + env[envname] = kwargs[argname].isoformat() + return self._runcmd(['git', 'commit-tree', tree, + '-p', parent, '-m', message], + env=env).strip() + def init(dirname): '''Initialise a new git repository.''' -- cgit v1.2.1