瀏覽代碼

Add test case for #479 #480

Benoit HERVIER 8 年之前
父節點
當前提交
aa4d6f6a7f
共有 1 個文件被更改,包括 42 次插入0 次删除
  1. 42 0
      dulwich/tests/test_index.py

+ 42 - 0
dulwich/tests/test_index.py

@@ -368,6 +368,48 @@ class BuildIndexTests(TestCase):
             self.assertEqual(['d'],
                 sorted(os.listdir(os.path.join(repo.path, 'c'))))
 
+    def test_norewrite(self):
+        repo_dir = tempfile.mkdtemp()
+        self.addCleanup(shutil.rmtree, repo_dir)
+        with Repo.init(repo_dir) as repo:
+
+            # Populate repo
+            filea = Blob.from_string(b'file a')
+            filea_path = os.path.join(repo_dir, 'a')
+            tree = Tree()
+            tree[b'a'] = (stat.S_IFREG | 0o644, filea.id)
+
+            repo.object_store.add_objects([(o, None)
+                for o in [filea, tree]])
+
+            # First Write
+            build_index_from_tree(repo.path, repo.index_path(),
+                                  repo.object_store, tree.id)
+            # Use sync as metadata can be cached on some FS
+            os.system('sync')
+            mtime = os.stat(filea_path).st_mtime
+
+            # Test Rewrite
+            build_index_from_tree(repo.path, repo.index_path(),
+                                  repo.object_store, tree.id)
+            os.system('sync')
+            self.assertEqual(mtime, 
+                             os.stat(filea_path).st_mtime)
+
+            # Modify content
+            with open(filea_path, 'wb') as fh:
+                fh.write(b'test a')
+            os.system('sync')
+            mtime = os.stat(filea_path).st_mtime
+ 
+            # Test rewrite
+            build_index_from_tree(repo.path, repo.index_path(),
+                                  repo.object_store, tree.id)
+            os.system('sync')
+            self.assertNotEqual(mtime, 
+                                os.stat(filea_path).st_mtime)
+
+
     @skipIf(not getattr(os, 'symlink', None), 'Requires symlink support')
     def test_symlink(self):
         repo_dir = tempfile.mkdtemp()