From: James Moger Date: Sat, 4 Feb 2012 03:49:14 +0000 (-0500) Subject: Setting to control display/serving non-bare repositories (issue 49) X-Git-Tag: v0.9.0~108 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=b86562942b1d4a498e337b28201e0db308fa51c8;p=gitblit.git Setting to control display/serving non-bare repositories (issue 49) --- diff --git a/distrib/gitblit.properties b/distrib/gitblit.properties index f6a8650e..0f7f7286 100644 --- a/distrib/gitblit.properties +++ b/distrib/gitblit.properties @@ -2,7 +2,9 @@ # Git Servlet Settings # -# Base folder for repositories +# Base folder for repositories. +# This folder may contain bare and non-bare repositories but Gitblit will only +# allow you to push to bare repositories. # Use forward slashes even on Windows!! # e.g. c:/gitrepos # @@ -28,6 +30,13 @@ git.searchRepositoriesSubfolders = true # SINCE 0.5.0 git.enableGitServlet = true +# Only serve/display bare repositories. +# If there are non-bare repositories in git.repositoriesFolder and this setting +# is true, they will be excluded from the ui. +# +# SINCE 0.9.0 +git.onlyAccessBareRepositories = false + # # Groovy Integration # diff --git a/docs/04_releases.mkd b/docs/04_releases.mkd index e5113192..1cd966e3 100644 --- a/docs/04_releases.mkd +++ b/docs/04_releases.mkd @@ -11,6 +11,8 @@ #### additions +- New setting to prevent display/serving non-bare repositories + **New:** *git.onlyAccessBareRepositories = false* - Allow relinking HEAD to a branch or a tag (Github/plm) #### fixes diff --git a/src/com/gitblit/GitBlit.java b/src/com/gitblit/GitBlit.java index 7a6411c4..7cb813fe 100644 --- a/src/com/gitblit/GitBlit.java +++ b/src/com/gitblit/GitBlit.java @@ -123,8 +123,6 @@ public class GitBlit implements ServletContextListener { private File repositoriesFolder; - private boolean exportAll = true; - private IUserService userService; private IStoredSettings settings; @@ -642,7 +640,8 @@ public class GitBlit implements ServletContextListener { * @return list of all repositories */ public List getRepositoryList() { - return JGitUtils.getRepositoryList(repositoriesFolder, exportAll, + return JGitUtils.getRepositoryList(repositoriesFolder, + settings.getBoolean(Keys.git.onlyAccessBareRepositories, false), settings.getBoolean(Keys.git.searchRepositoriesSubfolders, true)); } @@ -1767,7 +1766,7 @@ public class GitBlit implements ServletContextListener { this.settings = settings; repositoriesFolder = getRepositoriesFolder(); logger.info("Git repositories folder " + repositoriesFolder.getAbsolutePath()); - repositoryResolver = new FileResolver(repositoriesFolder, exportAll); + repositoryResolver = new FileResolver(repositoriesFolder, true); serverStatus = new ServerStatus(isGO()); String realm = settings.getString(Keys.realm.userService, "users.properties"); IUserService loginService = null; diff --git a/src/com/gitblit/utils/JGitUtils.java b/src/com/gitblit/utils/JGitUtils.java index c80fb8ae..1c155ff4 100644 --- a/src/com/gitblit/utils/JGitUtils.java +++ b/src/com/gitblit/utils/JGitUtils.java @@ -290,21 +290,21 @@ public class JGitUtils { * Returns a list of repository names in the specified folder. * * @param repositoriesFolder - * @param exportAll - * if true, all repositories are listed. If false only the - * repositories with a "git-daemon-export-ok" file are included + * @param onlyBare + * if true, only bare repositories repositories are listed. If + * false all repositories are included. * @param searchSubfolders * recurse into subfolders to find grouped repositories * @return list of repository names */ - public static List getRepositoryList(File repositoriesFolder, boolean exportAll, + public static List getRepositoryList(File repositoriesFolder, boolean onlyBare, boolean searchSubfolders) { List list = new ArrayList(); if (repositoriesFolder == null || !repositoriesFolder.exists()) { return list; } list.addAll(getRepositoryList(repositoriesFolder.getAbsolutePath(), repositoriesFolder, - exportAll, searchSubfolders)); + onlyBare, searchSubfolders)); StringUtils.sortRepositorynames(list); return list; } @@ -316,24 +316,21 @@ public class JGitUtils { * basePath is stripped from the repository name as repositories * are relative to this path * @param searchFolder - * @param exportAll - * if true all repositories are listed. If false only the - * repositories with a "git-daemon-export-ok" file are included + * @param onlyBare + * if true only bare repositories will be listed. if false all + * repositories are included. * @param searchSubfolders * recurse into subfolders to find grouped repositories * @return */ private static List getRepositoryList(String basePath, File searchFolder, - boolean exportAll, boolean searchSubfolders) { + boolean onlyBare, boolean searchSubfolders) { List list = new ArrayList(); for (File file : searchFolder.listFiles()) { if (file.isDirectory()) { File gitDir = FileKey.resolve(new File(searchFolder, file.getName()), FS.DETECTED); if (gitDir != null) { - boolean exportRepository = exportAll - || new File(gitDir, "git-daemon-export-ok").exists(); - - if (!exportRepository) { + if (onlyBare && gitDir.getName().equals(".git")) { continue; } // determine repository name relative to base path @@ -342,7 +339,7 @@ public class JGitUtils { list.add(repository); } else if (searchSubfolders && file.canRead()) { // look for repositories in subfolders - list.addAll(getRepositoryList(basePath, file, exportAll, searchSubfolders)); + list.addAll(getRepositoryList(basePath, file, onlyBare, searchSubfolders)); } } } diff --git a/tests/com/gitblit/tests/JGitUtilsTest.java b/tests/com/gitblit/tests/JGitUtilsTest.java index 8d70d2fa..d365bdea 100644 --- a/tests/com/gitblit/tests/JGitUtilsTest.java +++ b/tests/com/gitblit/tests/JGitUtilsTest.java @@ -66,7 +66,7 @@ public class JGitUtilsTest { @Test public void testFindRepositories() { - List list = JGitUtils.getRepositoryList(null, true, true); + List list = JGitUtils.getRepositoryList(null, false, true); assertEquals(0, list.size()); list.addAll(JGitUtils.getRepositoryList(new File("DoesNotExist"), true, true)); assertEquals(0, list.size());