# SINCE 1.0.1\r
git.searchRecursionDepth = -1\r
\r
+# List of regex exclusion patterns to match against folders found in\r
+# *git.repositoriesFolder*.\r
+# Use forward slashes even on Windows!!\r
+# e.g. test/jgit\.git\r
+#\r
+# SPACE-DELIMITED\r
+# CASE-SENSITIVE\r
+# SINCE 1.0.1\r
+git.searchExclusions =\r
+\r
# Allow push/pull over http/https with JGit servlet.\r
# If you do NOT want to allow Git clients to clone/push to Gitblit set this\r
# to false. You might want to do this if you are only using ssh:// or git://.\r
\r
#### changes\r
\r
-- Added *git.searchRecursionDepth=-1* to control how deep Gitblit will recurse into *git.repositoriesFolder* looking for repositories (issue 103)\r
+- Added setting to control how deep Gitblit will recurse into *git.repositoriesFolder* looking for repositories (issue 103)\r
+ **New:** *git.searchRecursionDepth=-1* \r
+- Added setting to specify regex exclusions for repositories (issue 103)\r
+ **New:** *git.searchExclusions=* \r
- Blob page now supports displaying images (issue 6)\r
- Non-image binary files can now be downloaded using the RAW link\r
- Updated Polish translation\r
\r
// determine available repositories\r
File folder = new File(params.folder);\r
- List<String> repoList = JGitUtils.getRepositoryList(folder, false, true, -1);\r
+ List<String> repoList = JGitUtils.getRepositoryList(folder, false, true, -1, null);\r
\r
int modCount = 0;\r
int skipCount = 0;\r
return JGitUtils.getRepositoryList(repositoriesFolder, \r
settings.getBoolean(Keys.git.onlyAccessBareRepositories, false),\r
settings.getBoolean(Keys.git.searchRepositoriesSubfolders, true),\r
- settings.getInteger(Keys.git.searchRecursionDepth, -1));\r
+ settings.getInteger(Keys.git.searchRecursionDepth, -1),\r
+ settings.getStrings(Keys.git.searchExclusions));\r
}\r
\r
/**\r
import java.util.List;\r
import java.util.Map;\r
import java.util.Map.Entry;\r
+import java.util.regex.Pattern;\r
import java.util.zip.ZipEntry;\r
import java.util.zip.ZipOutputStream;\r
\r
* recurse into subfolders to find grouped repositories\r
* @param depth\r
* optional recursion depth, -1 = infinite recursion\r
+ * @param exclusions\r
+ * list of regex exclusions for matching to folder names\r
* @return list of repository names\r
*/\r
public static List<String> getRepositoryList(File repositoriesFolder, boolean onlyBare,\r
- boolean searchSubfolders, int depth) {\r
+ boolean searchSubfolders, int depth, List<String> exclusions) {\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
- onlyBare, searchSubfolders, depth));\r
+ onlyBare, searchSubfolders, depth, exclusions));\r
StringUtils.sortRepositorynames(list);\r
return list;\r
}\r
* recurse into subfolders to find grouped repositories\r
* @param depth\r
* recursion depth, -1 = infinite recursion\r
+ * @param exclusions\r
+ * list of regex exclusions for matching to folder names\r
* @return\r
*/\r
private static List<String> getRepositoryList(String basePath, File searchFolder,\r
- boolean onlyBare, boolean searchSubfolders, int depth) {\r
+ boolean onlyBare, boolean searchSubfolders, int depth, List<String> exclusions) {\r
File baseFile = new File(basePath);\r
List<String> list = new ArrayList<String>();\r
if (depth == 0) {\r
return list;\r
}\r
+ List<Pattern> patterns = new ArrayList<Pattern>();\r
+ if (!ArrayUtils.isEmpty(exclusions)) {\r
+ for (String regex : exclusions) {\r
+ patterns.add(Pattern.compile(regex));\r
+ }\r
+ }\r
+ \r
int nextDepth = (depth == -1) ? -1 : depth - 1;\r
for (File file : searchFolder.listFiles()) {\r
if (file.isDirectory()) {\r
+ boolean exclude = false;\r
+ for (Pattern pattern : patterns) {\r
+ String path = FileUtils.getRelativePath(baseFile, file).replace('\\', '/');\r
+ if (pattern.matcher(path).find()) {\r
+ LOGGER.debug(MessageFormat.format("excluding {0} because of rule {1}", path, pattern.pattern()));\r
+ exclude = true;\r
+ break;\r
+ }\r
+ }\r
+ if (exclude) {\r
+ // skip to next file\r
+ continue;\r
+ }\r
+\r
File gitDir = FileKey.resolve(new File(searchFolder, file.getName()), FS.DETECTED);\r
if (gitDir != null) {\r
if (onlyBare && gitDir.getName().equals(".git")) {\r
list.add(repository);\r
} else if (searchSubfolders && file.canRead()) {\r
// look for repositories in subfolders\r
- list.addAll(getRepositoryList(basePath, file, onlyBare, searchSubfolders, nextDepth));\r
+ list.addAll(getRepositoryList(basePath, file, onlyBare, searchSubfolders,\r
+ nextDepth, exclusions));\r
}\r
} else if (searchSubfolders && file.canRead()) {\r
// look for repositories in subfolders\r
- list.addAll(getRepositoryList(basePath, file, onlyBare, searchSubfolders, nextDepth));\r
+ list.addAll(getRepositoryList(basePath, file, onlyBare, searchSubfolders,\r
+ nextDepth, exclusions));\r
}\r
}\r
}\r
\r
@Test\r
public void testFindRepositories() {\r
- List<String> list = JGitUtils.getRepositoryList(null, false, true, -1);\r
+ List<String> list = JGitUtils.getRepositoryList(null, false, true, -1, null);\r
assertEquals(0, list.size());\r
- list.addAll(JGitUtils.getRepositoryList(new File("DoesNotExist"), true, true, -1));\r
+ list.addAll(JGitUtils.getRepositoryList(new File("DoesNotExist"), true, true, -1, null));\r
assertEquals(0, list.size());\r
- list.addAll(JGitUtils.getRepositoryList(GitBlitSuite.REPOSITORIES, false, true, -1));\r
+ list.addAll(JGitUtils.getRepositoryList(GitBlitSuite.REPOSITORIES, false, true, -1, null));\r
assertTrue("No repositories found in " + GitBlitSuite.REPOSITORIES, list.size() > 0);\r
}\r
\r
+ @Test\r
+ public void testFindExclusions() {\r
+ List<String> list = JGitUtils.getRepositoryList(GitBlitSuite.REPOSITORIES, false, true, -1, null);\r
+ assertTrue("Missing jgit repository?!", list.contains("test/jgit.git"));\r
+\r
+ list = JGitUtils.getRepositoryList(GitBlitSuite.REPOSITORIES, false, true, -1, Arrays.asList("test/jgit\\.git"));\r
+ assertFalse("Repository exclusion failed!", list.contains("test/jgit.git"));\r
+\r
+ list = JGitUtils.getRepositoryList(GitBlitSuite.REPOSITORIES, false, true, -1, Arrays.asList("test/*"));\r
+ assertFalse("Repository exclusion failed!", list.contains("test/jgit.git"));\r
+\r
+ list = JGitUtils.getRepositoryList(GitBlitSuite.REPOSITORIES, false, true, -1, Arrays.asList("(jgit)+"));\r
+ assertFalse("Repository exclusion failed!", list.contains("test/jgit.git"));\r
+ assertFalse("Repository exclusion failed!", list.contains("working/jgit"));\r
+ assertFalse("Repository exclusion failed!", list.contains("working/jgit2"));\r
+\r
+ }\r
+\r
@Test\r
public void testOpenRepository() throws Exception {\r
Repository repository = GitBlitSuite.getHelloworldRepository();\r