2
0
Эх сурвалжийг харах

Properly handle files that are just executable for the current user. Fixes #734

Jelmer Vernooij 5 жил өмнө
parent
commit
e67d17665f

+ 3 - 0
NEWS

@@ -1,5 +1,8 @@
 0.19.15	UNRELEASED
 
+ * Properly handle files that are just executable for the
+   current user. (Jelmer Vernooij, #734)
+
 0.19.14	2019-11-30
 
  * Strip superfluous <> around email. (monnerat)

+ 3 - 2
dulwich/index.py

@@ -207,7 +207,8 @@ def cleanup_mode(mode):
     elif S_ISGITLINK(mode):
         return S_IFGITLINK
     ret = stat.S_IFREG | 0o644
-    ret |= (mode & 0o111)
+    if mode & 0o100:
+        ret |= 0o111
     return ret
 
 
@@ -326,7 +327,7 @@ class Index(object):
         """
         def lookup_entry(path):
             entry = self[path]
-            return entry.sha, entry.mode
+            return entry.sha, cleanup_mode(entry.mode)
         for (name, mode, sha) in changes_from_tree(
                 self._byname.keys(), lookup_entry, object_store, tree,
                 want_unchanged=want_unchanged):

+ 9 - 5
dulwich/tests/test_index.py

@@ -229,20 +229,24 @@ class CommitTreeTests(TestCase):
 
 class CleanupModeTests(TestCase):
 
+    def assertModeEqual(self, expected, got):
+        self.assertEqual(expected, got, '%o != %o' % (expected, got))
+
     def test_file(self):
-        self.assertEqual(0o100644, cleanup_mode(0o100000))
+        self.assertModeEqual(0o100644, cleanup_mode(0o100000))
 
     def test_executable(self):
-        self.assertEqual(0o100755, cleanup_mode(0o100711))
+        self.assertModeEqual(0o100755, cleanup_mode(0o100711))
+        self.assertModeEqual(0o100755, cleanup_mode(0o100700))
 
     def test_symlink(self):
-        self.assertEqual(0o120000, cleanup_mode(0o120711))
+        self.assertModeEqual(0o120000, cleanup_mode(0o120711))
 
     def test_dir(self):
-        self.assertEqual(0o040000, cleanup_mode(0o40531))
+        self.assertModeEqual(0o040000, cleanup_mode(0o40531))
 
     def test_submodule(self):
-        self.assertEqual(0o160000, cleanup_mode(0o160744))
+        self.assertModeEqual(0o160000, cleanup_mode(0o160744))
 
 
 class WriteCacheTimeTests(TestCase):