diff options
author | Richard Maw <richard.maw@codethink.co.uk> | 2015-04-28 18:43:39 +0000 |
---|---|---|
committer | Richard Ipsum <richard.ipsum@codethink.co.uk> | 2015-04-30 09:46:38 +0000 |
commit | c9ebfbf5793e25d4a094f7f6a8c81069c55874ba (patch) | |
tree | 02f92066871d3b4add7e3a162a8224152e8d4cfa /morphlib/gitdir.py | |
parent | ae172291e6e9a8e9eaa3fd09ecc643bb2a48f60f (diff) | |
download | morph-c9ebfbf5793e25d4a094f7f6a8c81069c55874ba.tar.gz |
GitDirectory: Add a store_commit method
commit-tree is usually sufficient, but I have a need to be able to
create a commit directly.
Change-Id: I80ba63eb9601aa1190554bb07522465ffb2cb5d9
Diffstat (limited to 'morphlib/gitdir.py')
-rw-r--r-- | morphlib/gitdir.py | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/morphlib/gitdir.py b/morphlib/gitdir.py index 5450db26..70f9db01 100644 --- a/morphlib/gitdir.py +++ b/morphlib/gitdir.py @@ -651,11 +651,24 @@ class GitDirectory(object): with fileno() method. ''' - if isinstance(blob_contents, basestring): - kwargs = {'feed_stdin': blob_contents} + return self._store_object(contents=blob_contents, type='blob') + + def store_commit(self, commit_contents): # pragma: no cover + '''Hash `commit_contents`, store it in git and return the sha1. + + `commit_contents` must either be a string or a value suitable to + pass to subprocess.Popen i.e. a file descriptor or file object + with fileno() method. + + ''' + return self._store_object(contents=commit_contents, type='commit') + + def _store_object(self, contents, type): + if isinstance(contents, basestring): + kwargs = {'feed_stdin': contents} else: - kwargs = {'stdin': blob_contents} - return morphlib.git.gitcmd(self._runcmd, 'hash-object', '-t', 'blob', + kwargs = {'stdin': contents} + return morphlib.git.gitcmd(self._runcmd, 'hash-object', '-t', type, '-w', '--stdin', **kwargs).strip() def commit_tree(self, tree, parent, message, **kwargs): |