Browse Source

Allow double-staging of files that are deleted in the index.

Change-Id: I92b75d09281d37c2486f77aa52680b8173379016
Dave Borowitz 15 years ago
parent
commit
02828bd47c
2 changed files with 10 additions and 1 deletions
  1. 4 1
      dulwich/repo.py
  2. 6 0
      dulwich/tests/test_repository.py

+ 4 - 1
dulwich/repo.py

@@ -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:

+ 6 - 0
dulwich/tests/test_repository.py

@@ -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.