From da34e56994d06e0df77902bb1fa7dfee11d3e9bf Mon Sep 17 00:00:00 2001
From: James Moger <james.moger@gitblit.com>
Date: Sun, 14 Jul 2013 12:05:19 -0400
Subject: [PATCH] Reset build identifiers for next development cycle
---
src/main/java/com/gitblit/AddIndexedBranch.java | 30 +++++++++++++++++++++++-------
1 files changed, 23 insertions(+), 7 deletions(-)
diff --git a/src/main/java/com/gitblit/AddIndexedBranch.java b/src/main/java/com/gitblit/AddIndexedBranch.java
index 67b7742..7a16bbd 100644
--- a/src/main/java/com/gitblit/AddIndexedBranch.java
+++ b/src/main/java/com/gitblit/AddIndexedBranch.java
@@ -25,15 +25,15 @@
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.lib.RepositoryCache.FileKey;
-import org.eclipse.jgit.storage.file.FileBasedConfig;
+import org.eclipse.jgit.lib.StoredConfig;
import org.eclipse.jgit.storage.file.FileRepositoryBuilder;
-import org.eclipse.jgit.internal.storage.file.FileRepository;
import org.eclipse.jgit.util.FS;
import com.beust.jcommander.JCommander;
import com.beust.jcommander.Parameter;
import com.beust.jcommander.ParameterException;
import com.beust.jcommander.Parameters;
+import com.gitblit.models.RefModel;
import com.gitblit.utils.ArrayUtils;
import com.gitblit.utils.JGitUtils;
import com.gitblit.utils.StringUtils;
@@ -84,16 +84,29 @@
continue;
}
- System.out.println(MessageFormat.format("adding [gitblit] indexBranch={0} for {1}", params.branch, repo));
+
try {
// load repository config
File gitDir = FileKey.resolve(new File(folder, repo), FS.DETECTED);
- FileRepository repository = (FileRepository)new FileRepositoryBuilder().setGitDir(gitDir).build();
- FileBasedConfig config = repository.getConfig();
+ Repository repository = new FileRepositoryBuilder().setGitDir(gitDir).build();
+ StoredConfig config = repository.getConfig();
config.load();
Set<String> indexedBranches = new LinkedHashSet<String>();
- indexedBranches.add(Constants.DEFAULT_BRANCH);
+
+ // add all local branches to index
+ if(params.addAllLocalBranches) {
+ List<RefModel> list = JGitUtils.getLocalBranches(repository, true, -1);
+ for (RefModel refModel : list) {
+ System.out.println(MessageFormat.format("adding [gitblit] indexBranch={0} for {1}", refModel.getName(), repo));
+ indexedBranches.add(refModel.getName());
+ }
+ }
+ else {
+ // add only one branch to index ('default' if not specified)
+ System.out.println(MessageFormat.format("adding [gitblit] indexBranch={0} for {1}", params.branch, repo));
+ indexedBranches.add(params.branch);
+ }
String [] branches = config.getStringList("gitblit", null, "indexBranch");
if (!ArrayUtils.isEmpty(branches)) {
@@ -124,10 +137,13 @@
@Parameter(names = { "--repositoriesFolder" }, description = "The root repositories folder ", required = true)
public String folder;
- @Parameter(names = { "--branch" }, description = "The branch to index", required = true)
+ @Parameter(names = { "--branch" }, description = "The branch to index", required = false)
public String branch = "default";
@Parameter(names = { "--skip" }, description = "Skip the named repository (simple fizzy matching is supported)", required = false)
public List<String> exclusions = new ArrayList<String>();
+
+ @Parameter(names = { "--all-local-branches" }, description = "Add all local branches to index. If specified, the --branch parameter is not considered.", required = false)
+ public boolean addAllLocalBranches = false;
}
}
--
Gitblit v1.9.1