فهرست منبع

Add tests for cleanup_mode.

Jelmer Vernooij 16 سال پیش
والد
کامیت
e8eb80f4b8
2فایلهای تغییر یافته به همراه33 افزوده شده و 6 حذف شده
  1. 14 6
      dulwich/index.py
  2. 19 0
      dulwich/tests/test_index.py

+ 14 - 6
dulwich/index.py

@@ -23,6 +23,8 @@ import stat
 import struct
 
 from dulwich.objects import (
+    S_IFGITLINK,
+    S_ISGITLINK,
     Tree,
     hex_to_sha,
     sha_to_hex,
@@ -132,12 +134,18 @@ def write_index_dict(f, entries):
 
 
 def cleanup_mode(mode):
-    if stat.S_ISLNK(fsmode):
-        mode = stat.S_IFLNK
-    else:
-        mode = stat.S_IFREG
-    mode |= (fsmode & 0111)
-    return mode
+    """Cleanup a mode value.
+    
+    """
+    if stat.S_ISLNK(mode):
+        return stat.S_IFLNK
+    elif stat.S_ISDIR(mode):
+        return stat.S_IFDIR
+    elif S_ISGITLINK(mode):
+        return S_IFGITLINK
+    ret = stat.S_IFREG | 0644
+    ret |= (mode & 0111)
+    return ret
 
 
 class Index(object):

+ 19 - 0
dulwich/tests/test_index.py

@@ -26,6 +26,7 @@ from unittest import TestCase
 
 from dulwich.index import (
     Index,
+    cleanup_mode,
     commit_tree,
     read_index,
     write_index,
@@ -104,3 +105,21 @@ class CommitTreeTests(TestCase):
         self.assertEquals((stat.S_IFREG, blob.id), self.store[dirid]["bar"])
         self.assertEquals(set([rootid, dirid, blob.id]), 
                           set(self.store._data.keys()))
+
+
+class CleanupModeTests(TestCase):
+
+    def test_file(self):
+        self.assertEquals(0100644, cleanup_mode(0100000))
+
+    def test_executable(self):
+        self.assertEquals(0100755, cleanup_mode(0100711))
+
+    def test_symlink(self):
+        self.assertEquals(0120000, cleanup_mode(0120711))
+
+    def test_dir(self):
+        self.assertEquals(0040000, cleanup_mode(040531))
+
+    def test_submodule(self):
+        self.assertEquals(0160000, cleanup_mode(0160744))