]> source.dussan.org Git - gitblit.git/commitdiff
Setting to control display/serving non-bare repositories (issue 49)
authorJames Moger <james.moger@gitblit.com>
Sat, 4 Feb 2012 03:49:14 +0000 (22:49 -0500)
committerJames Moger <james.moger@gitblit.com>
Sat, 4 Feb 2012 03:49:14 +0000 (22:49 -0500)
distrib/gitblit.properties
docs/04_releases.mkd
src/com/gitblit/GitBlit.java
src/com/gitblit/utils/JGitUtils.java
tests/com/gitblit/tests/JGitUtilsTest.java

index f6a8650e2db696c697269e3f739871b4d0533bbe..0f7f728621933f38e4b248ab8aeaa792600424f2 100644 (file)
@@ -2,7 +2,9 @@
 # Git Servlet Settings\r
 #\r
 \r
-# Base folder for repositories\r
+# Base folder for repositories.\r
+# This folder may contain bare and non-bare repositories but Gitblit will only\r
+# allow you to push to bare repositories.\r
 # Use forward slashes even on Windows!!\r
 # e.g. c:/gitrepos\r
 #\r
@@ -28,6 +30,13 @@ git.searchRepositoriesSubfolders = true
 # SINCE 0.5.0\r
 git.enableGitServlet = true\r
 \r
+# Only serve/display bare repositories.\r
+# If there are non-bare repositories in git.repositoriesFolder and this setting\r
+# is true, they will be excluded from the ui. \r
+#\r
+# SINCE 0.9.0\r
+git.onlyAccessBareRepositories = false\r
+\r
 #\r
 # Groovy Integration\r
 #\r
index e511319239c29f701520ce288992eb1fe5e48ef6..1cd966e352ccb1df8b0eba6f1c516dd8d971c733 100644 (file)
@@ -11,6 +11,8 @@
 \r
 #### additions\r
 \r
+- New setting to prevent display/serving non-bare repositories  \r
+    **New:** *git.onlyAccessBareRepositories = false*\r
 - Allow relinking HEAD to a branch or a tag (Github/plm)\r
 \r
 #### fixes \r
index 7a6411c48dfc658e161e32a06ee9e1a3d75587f2..7cb813fee31d3bd59fd29cf39d1f1e34ea968f6d 100644 (file)
@@ -123,8 +123,6 @@ public class GitBlit implements ServletContextListener {
 \r
        private File repositoriesFolder;\r
 \r
-       private boolean exportAll = true;\r
-\r
        private IUserService userService;\r
 \r
        private IStoredSettings settings;\r
@@ -642,7 +640,8 @@ public class GitBlit implements ServletContextListener {
         * @return list of all repositories\r
         */\r
        public List<String> getRepositoryList() {\r
-               return JGitUtils.getRepositoryList(repositoriesFolder, exportAll,\r
+               return JGitUtils.getRepositoryList(repositoriesFolder, \r
+                               settings.getBoolean(Keys.git.onlyAccessBareRepositories, false),\r
                                settings.getBoolean(Keys.git.searchRepositoriesSubfolders, true));\r
        }\r
 \r
@@ -1767,7 +1766,7 @@ public class GitBlit implements ServletContextListener {
                this.settings = settings;\r
                repositoriesFolder = getRepositoriesFolder();\r
                logger.info("Git repositories folder " + repositoriesFolder.getAbsolutePath());\r
-               repositoryResolver = new FileResolver<Void>(repositoriesFolder, exportAll);\r
+               repositoryResolver = new FileResolver<Void>(repositoriesFolder, true);\r
                serverStatus = new ServerStatus(isGO());\r
                String realm = settings.getString(Keys.realm.userService, "users.properties");\r
                IUserService loginService = null;\r
index c80fb8aeee89a12b9886cab08cdf78817d6ed039..1c155ff49f9752f9716c3b941e4de21eb42b0441 100644 (file)
@@ -290,21 +290,21 @@ public class JGitUtils {
         * Returns a list of repository names in the specified folder.\r
         * \r
         * @param repositoriesFolder\r
-        * @param exportAll\r
-        *            if true, all repositories are listed. If false only the\r
-        *            repositories with a "git-daemon-export-ok" file are included\r
+        * @param onlyBare\r
+        *            if true, only bare repositories repositories are listed. If\r
+        *            false all repositories are included.\r
         * @param searchSubfolders\r
         *            recurse into subfolders to find grouped repositories\r
         * @return list of repository names\r
         */\r
-       public static List<String> getRepositoryList(File repositoriesFolder, boolean exportAll,\r
+       public static List<String> getRepositoryList(File repositoriesFolder, boolean onlyBare,\r
                        boolean searchSubfolders) {\r
                List<String> list = new ArrayList<String>();\r
                if (repositoriesFolder == null || !repositoriesFolder.exists()) {\r
                        return list;\r
                }\r
                list.addAll(getRepositoryList(repositoriesFolder.getAbsolutePath(), repositoriesFolder,\r
-                               exportAll, searchSubfolders));\r
+                               onlyBare, searchSubfolders));\r
                StringUtils.sortRepositorynames(list);\r
                return list;\r
        }\r
@@ -316,24 +316,21 @@ public class JGitUtils {
         *            basePath is stripped from the repository name as repositories\r
         *            are relative to this path\r
         * @param searchFolder\r
-        * @param exportAll\r
-        *            if true all repositories are listed. If false only the\r
-        *            repositories with a "git-daemon-export-ok" file are included\r
+        * @param onlyBare\r
+        *            if true only bare repositories will be listed. if false all\r
+        *            repositories are included.\r
         * @param searchSubfolders\r
         *            recurse into subfolders to find grouped repositories\r
         * @return\r
         */\r
        private static List<String> getRepositoryList(String basePath, File searchFolder,\r
-                       boolean exportAll, boolean searchSubfolders) {\r
+                       boolean onlyBare, boolean searchSubfolders) {\r
                List<String> list = new ArrayList<String>();\r
                for (File file : searchFolder.listFiles()) {\r
                        if (file.isDirectory()) {\r
                                File gitDir = FileKey.resolve(new File(searchFolder, file.getName()), FS.DETECTED);\r
                                if (gitDir != null) {\r
-                                       boolean exportRepository = exportAll\r
-                                                       || new File(gitDir, "git-daemon-export-ok").exists();\r
-\r
-                                       if (!exportRepository) {\r
+                                       if (onlyBare && gitDir.getName().equals(".git")) {\r
                                                continue;\r
                                        }\r
                                        // determine repository name relative to base path\r
@@ -342,7 +339,7 @@ public class JGitUtils {
                                        list.add(repository);\r
                                } else if (searchSubfolders && file.canRead()) {\r
                                        // look for repositories in subfolders\r
-                                       list.addAll(getRepositoryList(basePath, file, exportAll, searchSubfolders));\r
+                                       list.addAll(getRepositoryList(basePath, file, onlyBare, searchSubfolders));\r
                                }\r
                        }\r
                }\r
index 8d70d2fa39efda557a346e83c1b93c8fdf5d459c..d365bdea7fd83961309095725c9ee9e0d0c0e1d0 100644 (file)
@@ -66,7 +66,7 @@ public class JGitUtilsTest {
 \r
        @Test\r
        public void testFindRepositories() {\r
-               List<String> list = JGitUtils.getRepositoryList(null, true, true);\r
+               List<String> list = JGitUtils.getRepositoryList(null, false, true);\r
                assertEquals(0, list.size());\r
                list.addAll(JGitUtils.getRepositoryList(new File("DoesNotExist"), true, true));\r
                assertEquals(0, list.size());\r