示例#1
0
 def test_readonly(self):
     f = GitFile(self.path('foo'), 'rb')
     self.assertTrue(isinstance(f, io.IOBase))
     self.assertEqual(b'foo contents', f.read())
     self.assertEqual(b'', f.read())
     f.seek(4)
     self.assertEqual(b'contents', f.read())
     f.close()
示例#2
0
 def read(self):
     """Read current contents of index from disk."""
     if not os.path.exists(self._filename):
         return
     f = GitFile(self._filename, 'rb')
     try:
         f = SHA1Reader(f)
         for x in read_index(f):
             self[x[0]] = IndexEntry(*x[1:])
         # FIXME: Additional data?
         f.read(os.path.getsize(self._filename) - f.tell() - 20)
         f.check_sha()
     finally:
         f.close()
示例#3
0
 def test_remove_packed_without_peeled(self):
     refs_file = os.path.join(self._repo.path, 'packed-refs')
     f = GitFile(refs_file)
     refs_data = f.read()
     f.close()
     f = GitFile(refs_file, 'wb')
     f.write(b'\n'.join(l for l in refs_data.split(b'\n')
                        if not l or l[0] not in b'#^'))
     f.close()
     self._repo = Repo(self._repo.path)
     refs = self._repo.refs
     self.assertTrue(
         refs.remove_if_equals(b'refs/heads/packed',
                               b'42d06bd4b77fed026b154d16493e5deab78f02ec'))
示例#4
0
 def test_default_mode(self):
     f = GitFile(self.path('foo'))
     self.assertEqual(b'foo contents', f.read())
     f.close()