]> source.dussan.org Git - gitblit.git/commitdiff
Fix setting wrrong custom mode on file and in config.
authorFlorian Zschocke <florian.zschocke@cycos.com>
Tue, 20 Aug 2013 19:20:17 +0000 (21:20 +0200)
committerFlorian Zschocke <florian.zschocke@cycos.com>
Mon, 26 Aug 2013 10:39:57 +0000 (12:39 +0200)
src/main/java/com/gitblit/utils/JGitUtils.java
src/test/java/com/gitblit/tests/JGitUtilsTest.java

index 57bb147f37848bfd405da1cf4b7d8fd224f24a6b..66dbd60d794af0587e04a702169e3dc3cc55b99d 100644 (file)
@@ -353,7 +353,10 @@ public class JGitUtils {
                }\r
 \r
                String getValue() {\r
-                       if ( enumValue == GitConfigSharedRepositoryValue.Oxxx ) return Integer.toOctalString(intValue);\r
+                       if ( enumValue == GitConfigSharedRepositoryValue.Oxxx ) {\r
+                               if (intValue == 0) return "0";\r
+                               return String.format("0%o", intValue);\r
+                       }\r
                        return enumValue.getConfigValue();\r
                }\r
 \r
@@ -410,7 +413,7 @@ public class JGitUtils {
 \r
                if (configShared.isCustom()) {\r
                        // Use the custom value for access permissions.\r
-                       mode |= (mode & ~0777) | perm;\r
+                       mode = (mode & ~0777) | perm;\r
                }\r
                else {\r
                        // Just add necessary bits to existing permissions.\r
index f18c05f8c008e279774728d38f4cba770ac0bc5f..cdf698d6da536b849246264e2227f763c1fd97ad 100644 (file)
@@ -182,6 +182,42 @@ public class JGitUtilsTest {
                }\r
        }\r
 \r
+       @Test\r
+       public void testCreateRepositorySharedCustom() throws Exception {\r
+               String[] repositories = { "NewSharedTestRepository.git" };\r
+               for (String repositoryName : repositories) {\r
+                       Repository repository = JGitUtils.createRepository(GitBlitSuite.REPOSITORIES,\r
+                                       repositoryName, "660");\r
+                       File folder = FileKey.resolve(new File(GitBlitSuite.REPOSITORIES, repositoryName),\r
+                                       FS.DETECTED);\r
+                       assertNotNull(repository);\r
+                       assertFalse(JGitUtils.hasCommits(repository));\r
+                       assertNull(JGitUtils.getFirstCommit(repository, null));\r
+\r
+                       assertEquals("0660", repository.getConfig().getString("core", null, "sharedRepository"));\r
+\r
+                       assertTrue(folder.exists());\r
+                       if (! JnaUtils.isWindows()) {\r
+                               int mode = JnaUtils.getFilemode(folder);\r
+                               assertEquals(JnaUtils.S_ISGID, mode & JnaUtils.S_ISGID);\r
+                               assertEquals(JnaUtils.S_IRWXG, mode & JnaUtils.S_IRWXG);\r
+                               assertEquals(0, mode & JnaUtils.S_IRWXO);\r
+\r
+                               mode = JnaUtils.getFilemode(folder.getAbsolutePath() + "/HEAD");\r
+                               assertEquals(JnaUtils.S_IRGRP | JnaUtils.S_IWGRP, mode & JnaUtils.S_IRWXG);\r
+                               assertEquals(0, mode & JnaUtils.S_IRWXO);\r
+\r
+                               mode = JnaUtils.getFilemode(folder.getAbsolutePath() + "/config");\r
+                               assertEquals(JnaUtils.S_IRGRP | JnaUtils.S_IWGRP, mode & JnaUtils.S_IRWXG);\r
+                               assertEquals(0, mode & JnaUtils.S_IRWXO);\r
+                       }\r
+\r
+                       repository.close();\r
+                       RepositoryCache.close(repository);\r
+                       FileUtils.delete(repository.getDirectory(), FileUtils.RECURSIVE);\r
+               }\r
+       }\r
+\r
        @Test\r
        public void testRefs() throws Exception {\r
                Repository repository = GitBlitSuite.getJGitRepository();\r