diff options
author | Richard Maw <richard.maw@codethink.co.uk> | 2013-11-11 17:25:13 +0000 |
---|---|---|
committer | Richard Maw <richard.maw@codethink.co.uk> | 2013-11-22 13:49:25 +0000 |
commit | d83d6ad7230eb27afae4169330681967bb20dcfa (patch) | |
tree | b58a3161b9314a3e7ed1db5e4cc5108fa49ab81a /morphlib/gitdir.py | |
parent | ef590d30ca978f57b658f59f584b9785f40ed0a5 (diff) | |
download | morph-d83d6ad7230eb27afae4169330681967bb20dcfa.tar.gz |
GitDir: add store_blob method
This is needed for making commits without touching the workspace.
Diffstat (limited to 'morphlib/gitdir.py')
-rw-r--r-- | morphlib/gitdir.py | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/morphlib/gitdir.py b/morphlib/gitdir.py index b08f69d2..4ba4cd9c 100644 --- a/morphlib/gitdir.py +++ b/morphlib/gitdir.py @@ -257,6 +257,21 @@ class GitDirectory(object): if code not in ('??', '!!'): yield code, to_path, from_path + def store_blob(self, blob_contents): + '''Hash `blob_contents`, store it in git and return the sha1. + + `blob_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. + + ''' + if isinstance(blob_contents, basestring): + kwargs = {'feed_stdin': blob_contents} + else: + kwargs = {'stdin': blob_contents} + return self._runcmd(['git', 'hash-object', '-t', 'blob', + '-w', '--stdin'], **kwargs).strip() + def init(dirname): '''Initialise a new git repository.''' |