Browse Source

Treat non-existent index files as empty.

Change-Id: Id9738a8fc6d3e53c6ef5b5b8d4144aaa5cd0e075
Dave Borowitz 15 years ago
parent
commit
97ea7f695a
2 changed files with 7 additions and 0 deletions
  1. 2 0
      dulwich/index.py
  2. 5 0
      dulwich/tests/test_index.py

+ 2 - 0
dulwich/index.py

@@ -204,6 +204,8 @@ class Index(object):
 
     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)

+ 5 - 0
dulwich/tests/test_index.py

@@ -68,6 +68,11 @@ class SimpleIndexTestCase(IndexTestCase):
                            'e69de29bb2d1d6434b8b29ae775ad8c2e48c5391', 0),
                           self.get_simple_index("index")["bla"])
 
+    def test_empty(self):
+        i = self.get_simple_index("notanindex")
+        self.assertEquals(0, len(i))
+        self.assertFalse(os.path.exists(i._filename))
+
 
 class SimpleIndexWriterTestCase(IndexTestCase):