diff options
-rw-r--r-- | lib/git/cmd.py | 1 | ||||
-rw-r--r-- | lib/git/objects/base.py | 12 | ||||
-rw-r--r-- | test/git/test_base.py | 13 |
3 files changed, 23 insertions, 3 deletions
diff --git a/lib/git/cmd.py b/lib/git/cmd.py index 27eb20e8..88d6008a 100644 --- a/lib/git/cmd.py +++ b/lib/git/cmd.py @@ -183,7 +183,6 @@ class Git(object): stdout=subprocess.PIPE, **extra ) - if as_process: return self.AutoInterrupt(proc) diff --git a/lib/git/objects/base.py b/lib/git/objects/base.py index dd67a3c7..0dfd1a23 100644 --- a/lib/git/objects/base.py +++ b/lib/git/objects/base.py @@ -127,6 +127,18 @@ class Object(LazyMixin): proc = self.repo.git.cat_file(self.type, self.id, as_process=True) return utils.ProcessStreamAdapter(proc, "stdout") + def stream_data(self, ostream): + """ + Writes our data directly to the given output stream + + ``ostream`` + File object compatible stream object. + + Returns + self + """ + self.repo.git.cat_file(self.type, self.id, output_stream=ostream) + return self class IndexObject(Object): """ diff --git a/test/git/test_base.py b/test/git/test_base.py index 4ad98d7f..b93e61c1 100644 --- a/test/git/test_base.py +++ b/test/git/test_base.py @@ -4,12 +4,15 @@ # This module is part of GitPython and is released under # the BSD License: http://www.opensource.org/licenses/bsd-license.php -from test.testlib import * -from git import * import git.objects.base as base import git.refs as refs +import os + +from test.testlib import * +from git import * from itertools import chain from git.objects.utils import get_object_type_by_name +import tempfile class TestBase(object): @@ -53,6 +56,12 @@ class TestBase(object): data_stream = item.data_stream data = data_stream.read() assert data + + tmpfile = os.tmpfile() + assert item == item.stream_data(tmpfile) + tmpfile.seek(0) + assert tmpfile.read() == data + # END stream to file directly # END for each object type to create # each has a unique sha |