Avoid stripping newlines in blob data.
authorJelmer Vernooij <jelmer@samba.org>
Sat, 26 Jul 2008 12:46:05 +0000 (14:46 +0200)
committerJelmer Vernooij <jelmer@samba.org>
Sat, 26 Jul 2008 12:46:05 +0000 (14:46 +0200)
lib/git/blob.py
test/fixtures/cat_file_blob_nl [new file with mode: 0644]
test/git/test_blob.py
test/git/test_repo.py

index a6768afb4c7de95a17fb7bc5e372cef1d459c331..fd83fe1df9e7913987656013ba5601641881a551 100644 (file)
@@ -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 (file)
index 0000000..802992c
--- /dev/null
@@ -0,0 +1 @@
+Hello world
index 68afdbd892ca1780c3d6d61040f2a0ecbfe337af..c4d8036cb742f380fd4bacd7b77b4ba7037a63c9 100644 (file)
@@ -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):
index 21b43a88fac030def3edbaaf824b5e6befdfd54f..ea3032c18ae6963b94a080eb91c50fe6592b0e5d 100644 (file)
@@ -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')