]> source.dussan.org Git - gitblit.git/commitdiff
add --all-local-branches to add all local branches of the repo to index 90/head
authorMichael Pailloncy <mpapo.dev@gmail.com>
Thu, 30 May 2013 20:23:34 +0000 (22:23 +0200)
committerMichael Pailloncy <mpapo.dev@gmail.com>
Thu, 30 May 2013 20:23:34 +0000 (22:23 +0200)
src/main/java/com/gitblit/AddIndexedBranch.java

index 6ae424ec9828dfd83d50738c79df13379487138a..7a16bbd96fce3ba98956c4a423751597d9351b1a 100644 (file)
@@ -33,6 +33,7 @@ import com.beust.jcommander.JCommander;
 import com.beust.jcommander.Parameter;\r
 import com.beust.jcommander.ParameterException;\r
 import com.beust.jcommander.Parameters;\r
+import com.gitblit.models.RefModel;\r
 import com.gitblit.utils.ArrayUtils;\r
 import com.gitblit.utils.JGitUtils;\r
 import com.gitblit.utils.StringUtils;\r
@@ -83,7 +84,7 @@ public class AddIndexedBranch {
                                continue;\r
                        }\r
 \r
-                       System.out.println(MessageFormat.format("adding [gitblit] indexBranch={0} for {1}", params.branch, repo));\r
+                       \r
                        try {\r
                                // load repository config\r
                                File gitDir = FileKey.resolve(new File(folder, repo), FS.DETECTED);\r
@@ -92,7 +93,20 @@ public class AddIndexedBranch {
                                config.load();\r
                                \r
                                Set<String> indexedBranches = new LinkedHashSet<String>();\r
-                               indexedBranches.add(params.branch);\r
+                               \r
+                               // add all local branches to index\r
+                               if(params.addAllLocalBranches) {\r
+                                       List<RefModel> list = JGitUtils.getLocalBranches(repository, true, -1);\r
+                                       for (RefModel refModel : list) {\r
+                                               System.out.println(MessageFormat.format("adding [gitblit] indexBranch={0} for {1}", refModel.getName(), repo));\r
+                                               indexedBranches.add(refModel.getName());\r
+                                       }\r
+                               }\r
+                               else {\r
+                                       // add only one branch to index ('default' if not specified)\r
+                                       System.out.println(MessageFormat.format("adding [gitblit] indexBranch={0} for {1}", params.branch, repo));\r
+                                       indexedBranches.add(params.branch);\r
+                               }\r
                                \r
                                String [] branches = config.getStringList("gitblit", null, "indexBranch");\r
                                if (!ArrayUtils.isEmpty(branches)) {\r
@@ -123,10 +137,13 @@ public class AddIndexedBranch {
                @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
+               @Parameter(names = { "--branch" }, description = "The branch to index", required = false)\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
+               @Parameter(names = { "--all-local-branches" }, description = "Add all local branches to index. If specified, the --branch parameter is not considered.", required = false)\r
+               public boolean addAllLocalBranches = false;\r
        }\r
 }\r