Allow double-staging of files that are deleted in the index.
authorDave Borowitz <dborowitz@google.com>
Mon, 3 May 2010 23:44:05 +0000 (16:44 -0700)
committerDave Borowitz <dborowitz@google.com>
Wed, 12 May 2010 16:40:22 +0000 (09:40 -0700)
Change-Id: I92b75d09281d37c2486f77aa52680b8173379016

dulwich/repo.py
dulwich/tests/test_repository.py

index 087ad56..6cf5df1 100644 (file)
@@ -1126,7 +1126,10 @@ class Repo(BaseRepo):
                 st = os.stat(full_path)
             except OSError:
                 # File no longer exists
-                del index[path]
+                try:
+                    del index[path]
+                except KeyError:
+                    pass  # Doesn't exist in the index either
             else:
                 f = open(full_path, 'rb')
                 try:
index 3a307f7..9918e02 100644 (file)
@@ -403,6 +403,12 @@ class BuildRepoTests(unittest.TestCase):
         self.assertEqual(r[self._root_commit].tree, new_commit.tree)
         self.assertEqual('failed commit', new_commit.message)
 
+    def test_stage_deleted(self):
+        r = self._repo
+        os.remove(os.path.join(r.path, 'a'))
+        r.stage(['a'])
+        r.stage(['a'])  # double-stage a deleted path
+
 
 class CheckRefFormatTests(unittest.TestCase):
     """Tests for the check_ref_format function.