Browse Source

Merge branch 'symlinks' of git://github.com/garyvdm/dulwich

Jelmer Vernooij 10 years ago
parent
commit
fbe28d8a17
2 changed files with 41 additions and 21 deletions
  1. 39 19
      dulwich/tests/test_index.py
  2. 2 2
      dulwich/tests/test_repository.py

+ 39 - 19
dulwich/tests/test_index.py

@@ -25,6 +25,7 @@ import os
 import shutil
 import stat
 import struct
+import sys
 import tempfile
 
 from dulwich.index import (
@@ -50,7 +51,10 @@ from dulwich.objects import (
     Tree,
     )
 from dulwich.repo import Repo
-from dulwich.tests import TestCase
+from dulwich.tests import (
+    TestCase,
+    skipIf,
+)
 
 class IndexTestCase(TestCase):
 
@@ -272,9 +276,6 @@ class BuildIndexTests(TestCase):
             self.assertEqual(['.git'], os.listdir(repo.path))
 
     def test_git_dir(self):
-        if os.name != 'posix':
-            self.skipTest("test depends on POSIX shell")
-
         repo_dir = tempfile.mkdtemp()
         self.addCleanup(shutil.rmtree, repo_dir)
         with closing(Repo.init(repo_dir)) as repo:
@@ -309,9 +310,6 @@ class BuildIndexTests(TestCase):
             self.assertFileContents(epath, b'd')
 
     def test_nonempty(self):
-        if os.name != 'posix':
-            self.skipTest("test depends on POSIX shell")
-
         repo_dir = tempfile.mkdtemp()
         self.addCleanup(shutil.rmtree, repo_dir)
         with closing(Repo.init(repo_dir)) as repo:
@@ -320,23 +318,21 @@ class BuildIndexTests(TestCase):
             filea = Blob.from_string(b'file a')
             fileb = Blob.from_string(b'file b')
             filed = Blob.from_string(b'file d')
-            filee = Blob.from_string(b'd')
 
             tree = Tree()
             tree[b'a'] = (stat.S_IFREG | 0o644, filea.id)
             tree[b'b'] = (stat.S_IFREG | 0o644, fileb.id)
             tree[b'c/d'] = (stat.S_IFREG | 0o644, filed.id)
-            tree[b'c/e'] = (stat.S_IFLNK, filee.id)  # symlink
 
             repo.object_store.add_objects([(o, None)
-                for o in [filea, fileb, filed, filee, tree]])
+                for o in [filea, fileb, filed, tree]])
 
             build_index_from_tree(repo.path, repo.index_path(),
                     repo.object_store, tree.id)
 
             # Verify index entries
             index = repo.open_index()
-            self.assertEqual(len(index), 4)
+            self.assertEqual(len(index), 3)
 
             # filea
             apath = os.path.join(repo.path, 'a')
@@ -359,19 +355,43 @@ class BuildIndexTests(TestCase):
                 stat.S_IFREG | 0o644, 6, filed.id)
             self.assertFileContents(dpath, b'file d')
 
-            # symlink to d
-            epath = os.path.join(repo.path, 'c', 'e')
-            self.assertTrue(os.path.exists(epath))
-            self.assertReasonableIndexEntry(index[b'c/e'],
-                stat.S_IFLNK, 1, filee.id)
-            self.assertFileContents(epath, 'd', symlink=True)
-
             # Verify no extra files
             self.assertEqual(['.git', 'a', 'b', 'c'],
                 sorted(os.listdir(repo.path)))
-            self.assertEqual(['d', 'e'],
+            self.assertEqual(['d'],
                 sorted(os.listdir(os.path.join(repo.path, 'c'))))
 
+    @skipIf(not getattr(os, 'symlink', None), 'Requires symlink support')
+    def test_symlink(self):
+        repo_dir = tempfile.mkdtemp()
+        self.addCleanup(shutil.rmtree, repo_dir)
+        with closing(Repo.init(repo_dir)) as repo:
+
+            # Populate repo
+            filed = Blob.from_string(b'file d')
+            filee = Blob.from_string(b'd')
+
+            tree = Tree()
+            tree[b'c/d'] = (stat.S_IFREG | 0o644, filed.id)
+            tree[b'c/e'] = (stat.S_IFLNK, filee.id)  # symlink
+
+            repo.object_store.add_objects([(o, None)
+                for o in [filed, filee, tree]])
+
+            build_index_from_tree(repo.path, repo.index_path(),
+                    repo.object_store, tree.id)
+
+            # Verify index entries
+            index = repo.open_index()
+
+            # symlink to d
+            epath = os.path.join(repo.path, 'c', 'e')
+            self.assertTrue(os.path.exists(epath))
+            self.assertReasonableIndexEntry(
+                index[b'c/e'], stat.S_IFLNK,
+                0 if sys.platform == 'win32' else 1,
+                filee.id)
+            self.assertFileContents(epath, 'd', symlink=True)
 
 class GetUnstagedChangesTests(TestCase):
 

+ 2 - 2
dulwich/tests/test_repository.py

@@ -305,7 +305,7 @@ class RepositoryRootTests(TestCase):
         r = self.open_repo('ooo_merge.git')
         self.assertIsInstance(r.get_config_stack(), Config)
 
-    @skipIf(sys.platform == 'win32', 'Requires symlink support')
+    @skipIf(not getattr(os, 'symlink', None), 'Requires symlink support')
     def test_submodule(self):
         temp_dir = self.mkdtemp()
         self.addCleanup(shutil.rmtree, temp_dir)
@@ -565,7 +565,7 @@ class BuildRepoRootTests(TestCase):
         self.assertEqual(stat.S_IFREG | 0o644, a_mode)
         self.assertEqual(b'new contents', r[a_id].data)
 
-    @skipIf(sys.platform == 'win32', 'Requires symlink support')
+    @skipIf(not getattr(os, 'symlink', None), 'Requires symlink support')
     def test_commit_symlink(self):
         r = self._repo
         os.symlink('a', os.path.join(r.path, 'b'))