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 a6768af..fd83fe1 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 68afdbd..c4d8036 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 21b43a8..ea3032c 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')