From 14cef2bb3e0de02f306fa37c268d6c276326c002 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 26 Jul 2008 14:46:05 +0200 Subject: Avoid stripping newlines in blob data. (cherry picked from commit ccca12ee26e40fb4c4df2d77154ed496144569b9) --- lib/git/blob.py | 2 +- test/fixtures/cat_file_blob_nl | 1 + test/git/test_blob.py | 12 ++++++++++-- test/git/test_repo.py | 2 +- 4 files changed, 13 insertions(+), 4 deletions(-) create mode 100644 test/fixtures/cat_file_blob_nl diff --git a/lib/git/blob.py b/lib/git/blob.py index a6768afb..fd83fe1d 100644 --- a/lib/git/blob.py +++ b/lib/git/blob.py @@ -57,7 +57,7 @@ class Blob(object): Returns str """ - self.data_stored = self.data_stored or self.repo.git.cat_file(self.id, **{'p': True}) + self.data_stored = self.data_stored or self.repo.git.cat_file(self.id, **{'p': True, 'with_raw_output': True}) return self.data_stored @property diff --git a/test/fixtures/cat_file_blob_nl b/test/fixtures/cat_file_blob_nl new file mode 100644 index 00000000..802992c4 --- /dev/null +++ b/test/fixtures/cat_file_blob_nl @@ -0,0 +1 @@ +Hello world diff --git a/test/git/test_blob.py b/test/git/test_blob.py index 68afdbd8..c4d8036c 100644 --- a/test/git/test_blob.py +++ b/test/git/test_blob.py @@ -18,7 +18,15 @@ class TestBlob(object): blob = Blob(self.repo, **{'id': 'abc'}) assert_equal("Hello world", blob.data) assert_true(git.called) - assert_equal(git.call_args, (('cat_file', 'abc'), {'p': True})) + assert_equal(git.call_args, (('cat_file', 'abc'), {'p': True, 'with_raw_output': True})) + + @patch(Git, '_call_process') + def test_should_return_blob_contents_with_newline(self, git): + git.return_value = fixture('cat_file_blob_nl') + blob = Blob(self.repo, **{'id': 'abc'}) + assert_equal("Hello world\n", blob.data) + assert_true(git.called) + assert_equal(git.call_args, (('cat_file', 'abc'), {'p': True, 'with_raw_output': True})) @patch(Git, '_call_process') def test_should_cache_data(self, git): @@ -28,7 +36,7 @@ class TestBlob(object): blob.data assert_true(git.called) assert_equal(git.call_count, 1) - assert_equal(git.call_args, (('cat_file', 'abc'), {'p': True})) + assert_equal(git.call_args, (('cat_file', 'abc'), {'p': True, 'with_raw_output': True})) @patch(Git, '_call_process') def test_should_return_file_size(self, git): diff --git a/test/git/test_repo.py b/test/git/test_repo.py index 21b43a88..ea3032c1 100644 --- a/test/git/test_repo.py +++ b/test/git/test_repo.py @@ -107,7 +107,7 @@ class TestRepo(object): assert_equal("Hello world", blob.data) assert_true(git.called) - assert_equal(git.call_args, (('cat_file', 'abc'), {'p': True})) + assert_equal(git.call_args, (('cat_file', 'abc'), {'p': True, 'with_raw_output': True})) @patch(Repo, '__init__') @patch(Git, '_call_process') -- cgit v1.2.3