--- /dev/null
+@REM --------------------------------------------------------------------------\r
+@REM This is for Lucene search integration.\r
+@REM\r
+@REM Allows you to add an indexed branch specification to the repository config\r
+@REM for all matching repositories in the specified folder.\r
+@REM\r
+@REM All repositories are included unless excluded using a --skip parameter.\r
+@REM --skip supports simple wildcard fuzzy matching however only 1 asterisk is\r
+@REM allowed per parameter.\r
+@REM\r
+@REM Always use forward-slashes for the path separator in your parameters!!\r
+@REM\r
+@REM Set FOLDER to the server's git.repositoriesFolder\r
+@REM Set BRANCH ("default" or fully qualified ref - i.e. refs/heads/master)\r
+@REM Set EXCLUSIONS for any repositories that you do not want to change\r
+@REM --------------------------------------------------------------------------\r
+@SET FOLDER=c:/gitblit/git\r
+@SET EXCLUSIONS=--skip test.git --skip group/test*\r
+@SET BRANCH=default\r
+@java -cp gitblit.jar;"%CD%\ext\*" com.gitblit.AddIndexedBranch --repositoriesFolder %FOLDER% --branch %BRANCH% %EXCLUSIONS%\r
--- /dev/null
+/*\r
+ * Copyright 2012 gitblit.com.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+package com.gitblit;\r
+\r
+import java.io.File;\r
+import java.text.MessageFormat;\r
+import java.util.ArrayList;\r
+import java.util.LinkedHashSet;\r
+import java.util.List;\r
+import java.util.Set;\r
+import java.util.TreeSet;\r
+\r
+import org.eclipse.jgit.lib.RepositoryCache.FileKey;\r
+import org.eclipse.jgit.storage.file.FileBasedConfig;\r
+import org.eclipse.jgit.storage.file.FileRepository;\r
+import org.eclipse.jgit.util.FS;\r
+\r
+import com.beust.jcommander.JCommander;\r
+import com.beust.jcommander.Parameter;\r
+import com.beust.jcommander.ParameterException;\r
+import com.beust.jcommander.Parameters;\r
+import com.gitblit.utils.ArrayUtils;\r
+import com.gitblit.utils.JGitUtils;\r
+import com.gitblit.utils.StringUtils;\r
+\r
+/**\r
+ * Utility class to add an indexBranch setting to matching repositories.\r
+ * \r
+ * @author James Moger\r
+ * \r
+ */\r
+public class AddIndexedBranch {\r
+\r
+ public static void main(String... args) {\r
+ Params params = new Params();\r
+ JCommander jc = new JCommander(params);\r
+ try {\r
+ jc.parse(args);\r
+ } catch (ParameterException t) {\r
+ System.err.println(t.getMessage());\r
+ jc.usage();\r
+ return;\r
+ }\r
+ \r
+ // create a lowercase set of excluded repositories\r
+ Set<String> exclusions = new TreeSet<String>();\r
+ for (String exclude : params.exclusions) {\r
+ exclusions.add(exclude.toLowerCase());\r
+ }\r
+ \r
+ // determine available repositories\r
+ File folder = new File(params.folder);\r
+ List<String> repoList = JGitUtils.getRepositoryList(folder, false, true);\r
+ \r
+ int modCount = 0;\r
+ int skipCount = 0;\r
+ for (String repo : repoList) {\r
+ boolean skip = false;\r
+ for (String exclusion : exclusions) {\r
+ if (StringUtils.fuzzyMatch(repo, exclusion)) {\r
+ skip = true;\r
+ break;\r
+ }\r
+ }\r
+ \r
+ if (skip) {\r
+ System.out.println("skipping " + repo);\r
+ skipCount++;\r
+ continue;\r
+ }\r
+\r
+ System.out.println(MessageFormat.format("adding [gitblit] indexBranch={0} for {1}", params.branch, repo));\r
+ try {\r
+ // load repository config\r
+ File gitDir = FileKey.resolve(new File(folder, repo), FS.DETECTED);\r
+ FileRepository repository = new FileRepository(gitDir);\r
+ FileBasedConfig config = repository.getConfig();\r
+ config.load();\r
+ \r
+ Set<String> indexedBranches = new LinkedHashSet<String>();\r
+ indexedBranches.add(Constants.DEFAULT_BRANCH);\r
+ \r
+ String [] branches = config.getStringList("gitblit", null, "indexBranch");\r
+ if (!ArrayUtils.isEmpty(branches)) {\r
+ for (String branch : branches) {\r
+ indexedBranches.add(branch);\r
+ }\r
+ }\r
+ config.setStringList("gitblit", null, "indexBranch", new ArrayList<String>(indexedBranches));\r
+ config.save();\r
+ modCount++;\r
+ } catch (Exception e) {\r
+ System.err.println(repo);\r
+ e.printStackTrace();\r
+ }\r
+ }\r
+ \r
+ System.out.println(MessageFormat.format("updated {0} repository configurations, skipped {1}", modCount, skipCount));\r
+ }\r
+\r
+ \r
+\r
+ /**\r
+ * JCommander Parameters class for AddIndexedBranch.\r
+ */\r
+ @Parameters(separators = " ")\r
+ private static class Params {\r
+\r
+ @Parameter(names = { "--repositoriesFolder" }, description = "The root repositories folder ", required = true)\r
+ public String folder;\r
+\r
+ @Parameter(names = { "--branch" }, description = "The branch to index", required = true)\r
+ public String branch = "default";\r
+\r
+ @Parameter(names = { "--skip" }, description = "Skip the named repository (simple fizzy matching is supported)", required = false)\r
+ public List<String> exclusions = new ArrayList<String>();\r
+ }\r
+}\r