| | |
| | | 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;
|
| | |
|
| | | /**
|
| | | * Utility class to add an indexBranch setting to matching repositories.
|
| | | * |
| | | *
|
| | | * @author James Moger
|
| | | * |
| | | *
|
| | | */
|
| | | public class AddIndexedBranch {
|
| | |
|
| | |
| | | jc.usage();
|
| | | return;
|
| | | }
|
| | | |
| | |
|
| | | // create a lowercase set of excluded repositories
|
| | | Set<String> exclusions = new TreeSet<String>();
|
| | | for (String exclude : params.exclusions) {
|
| | | exclusions.add(exclude.toLowerCase());
|
| | | }
|
| | | |
| | |
|
| | | // determine available repositories
|
| | | File folder = new File(params.folder);
|
| | | List<String> repoList = JGitUtils.getRepositoryList(folder, false, true, -1, null);
|
| | | |
| | |
|
| | | int modCount = 0;
|
| | | int skipCount = 0;
|
| | | for (String repo : repoList) {
|
| | |
| | | break;
|
| | | }
|
| | | }
|
| | | |
| | |
|
| | | if (skip) {
|
| | | System.out.println("skipping " + repo);
|
| | | skipCount++;
|
| | | 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);
|
| | | 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)) {
|
| | | for (String branch : branches) {
|
| | |
| | | e.printStackTrace();
|
| | | }
|
| | | }
|
| | | |
| | |
|
| | | System.out.println(MessageFormat.format("updated {0} repository configurations, skipped {1}", modCount, skipCount));
|
| | | }
|
| | |
|
| | | |
| | |
|
| | |
|
| | | /**
|
| | | * JCommander Parameters class for AddIndexedBranch.
|
| | |
| | | @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;
|
| | | }
|
| | | }
|