Florian Zschocke
2013-08-20 8b5730a0e32d5707b6ac6df5fb0906b7981853eb
Fix setting wrrong custom mode on file and in config.
2 files modified
43 ■■■■■ changed files
src/main/java/com/gitblit/utils/JGitUtils.java 7 ●●●● patch | view | raw | blame | history
src/test/java/com/gitblit/tests/JGitUtilsTest.java 36 ●●●●● patch | view | raw | blame | history
src/main/java/com/gitblit/utils/JGitUtils.java
@@ -353,7 +353,10 @@
        }
        String getValue() {
            if ( enumValue == GitConfigSharedRepositoryValue.Oxxx ) return Integer.toOctalString(intValue);
            if ( enumValue == GitConfigSharedRepositoryValue.Oxxx ) {
                if (intValue == 0) return "0";
                return String.format("0%o", intValue);
            }
            return enumValue.getConfigValue();
        }
@@ -410,7 +413,7 @@
        if (configShared.isCustom()) {
            // Use the custom value for access permissions.
            mode |= (mode & ~0777) | perm;
            mode = (mode & ~0777) | perm;
        }
        else {
            // Just add necessary bits to existing permissions.
src/test/java/com/gitblit/tests/JGitUtilsTest.java
@@ -183,6 +183,42 @@
    }
    @Test
    public void testCreateRepositorySharedCustom() throws Exception {
        String[] repositories = { "NewSharedTestRepository.git" };
        for (String repositoryName : repositories) {
            Repository repository = JGitUtils.createRepository(GitBlitSuite.REPOSITORIES,
                    repositoryName, "660");
            File folder = FileKey.resolve(new File(GitBlitSuite.REPOSITORIES, repositoryName),
                    FS.DETECTED);
            assertNotNull(repository);
            assertFalse(JGitUtils.hasCommits(repository));
            assertNull(JGitUtils.getFirstCommit(repository, null));
            assertEquals("0660", repository.getConfig().getString("core", null, "sharedRepository"));
            assertTrue(folder.exists());
            if (! JnaUtils.isWindows()) {
                int mode = JnaUtils.getFilemode(folder);
                assertEquals(JnaUtils.S_ISGID, mode & JnaUtils.S_ISGID);
                assertEquals(JnaUtils.S_IRWXG, mode & JnaUtils.S_IRWXG);
                assertEquals(0, mode & JnaUtils.S_IRWXO);
                mode = JnaUtils.getFilemode(folder.getAbsolutePath() + "/HEAD");
                assertEquals(JnaUtils.S_IRGRP | JnaUtils.S_IWGRP, mode & JnaUtils.S_IRWXG);
                assertEquals(0, mode & JnaUtils.S_IRWXO);
                mode = JnaUtils.getFilemode(folder.getAbsolutePath() + "/config");
                assertEquals(JnaUtils.S_IRGRP | JnaUtils.S_IWGRP, mode & JnaUtils.S_IRWXG);
                assertEquals(0, mode & JnaUtils.S_IRWXO);
            }
            repository.close();
            RepositoryCache.close(repository);
            FileUtils.delete(repository.getDirectory(), FileUtils.RECURSIVE);
        }
    }
    @Test
    public void testRefs() throws Exception {
        Repository repository = GitBlitSuite.getJGitRepository();
        Map<ObjectId, List<RefModel>> map = JGitUtils.getAllRefs(repository);