use of org.eclipse.jgit.storage.file.FileRepositoryBuilder in project gitblit by gitblit.
the class AddIndexedBranch method main.
public static void main(String... args) {
Params params = new Params();
CmdLineParser parser = new CmdLineParser(params);
try {
parser.parseArgument(args);
} catch (CmdLineException t) {
System.err.println(t.getMessage());
parser.printUsage(System.out);
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) {
boolean skip = false;
for (String exclusion : exclusions) {
if (StringUtils.fuzzyMatch(repo, exclusion)) {
skip = true;
break;
}
}
if (skip) {
System.out.println("skipping " + repo);
skipCount++;
continue;
}
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>();
// 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) {
indexedBranches.add(branch);
}
}
config.setStringList("gitblit", null, "indexBranch", new ArrayList<String>(indexedBranches));
config.save();
modCount++;
} catch (Exception e) {
System.err.println(repo);
e.printStackTrace();
}
}
System.out.println(MessageFormat.format("updated {0} repository configurations, skipped {1}", modCount, skipCount));
}
use of org.eclipse.jgit.storage.file.FileRepositoryBuilder in project gitblit by gitblit.
the class JGitUtils method cloneRepository.
/**
* Clone or Fetch a repository. If the local repository does not exist,
* clone is called. If the repository does exist, fetch is called. By
* default the clone/fetch retrieves the remote heads, tags, and notes.
*
* @param repositoriesFolder
* @param name
* @param fromUrl
* @param bare
* @param credentialsProvider
* @return CloneResult
* @throws Exception
*/
public static CloneResult cloneRepository(File repositoriesFolder, String name, String fromUrl, boolean bare, CredentialsProvider credentialsProvider) throws Exception {
CloneResult result = new CloneResult();
if (bare) {
// bare repository, ensure .git suffix
if (!name.toLowerCase().endsWith(Constants.DOT_GIT_EXT)) {
name += Constants.DOT_GIT_EXT;
}
} else {
// normal repository, strip .git suffix
if (name.toLowerCase().endsWith(Constants.DOT_GIT_EXT)) {
name = name.substring(0, name.indexOf(Constants.DOT_GIT_EXT));
}
}
result.name = name;
File folder = new File(repositoriesFolder, name);
if (folder.exists()) {
File gitDir = FileKey.resolve(new File(repositoriesFolder, name), FS.DETECTED);
Repository repository = new FileRepositoryBuilder().setGitDir(gitDir).build();
result.fetchResult = fetchRepository(credentialsProvider, repository);
repository.close();
} else {
CloneCommand clone = new CloneCommand();
clone.setBare(bare);
clone.setCloneAllBranches(true);
clone.setURI(fromUrl);
clone.setDirectory(folder);
if (credentialsProvider != null) {
clone.setCredentialsProvider(credentialsProvider);
}
Repository repository = clone.call().getRepository();
// Now we have to fetch because CloneCommand doesn't fetch
// refs/notes nor does it allow manual RefSpec.
result.createdRepository = true;
result.fetchResult = fetchRepository(credentialsProvider, repository);
repository.close();
}
return result;
}
use of org.eclipse.jgit.storage.file.FileRepositoryBuilder in project Aeron by real-logic.
the class TutorialPublishTask method getWikiUri.
private String getWikiUri() throws IOException, URISyntaxException {
final File baseGitDir = new File(getProject().getRootDir(), ".git");
if (!baseGitDir.exists() || !baseGitDir.isDirectory()) {
throw new IllegalStateException("unable to find valid git repository at: " + baseGitDir);
}
final Repository baseGitRepo = new FileRepositoryBuilder().setGitDir(new File(getProject().getRootDir(), ".git")).build();
final String origin = baseGitRepo.getConfig().getString(CONFIG_REMOTE_SECTION, requireNonNull(remoteName, "'remoteName' must be set, use origin as a default"), CONFIG_KEY_URL);
if (null == origin) {
throw new IllegalStateException("unable to find origin URI");
}
return GithubUtil.getWikiUriFromOriginUri(origin);
}
use of org.eclipse.jgit.storage.file.FileRepositoryBuilder in project camel by apache.
the class GitProducer method getLocalRepository.
private Repository getLocalRepository() throws IOException {
FileRepositoryBuilder builder = new FileRepositoryBuilder();
Repository repo = null;
try {
repo = // scan
builder.setGitDir(new File(endpoint.getLocalPath(), ".git")).readEnvironment().findGitDir().build();
} catch (IOException e) {
LOG.error("There was an error, cannot open " + endpoint.getLocalPath() + " repository");
throw e;
}
return repo;
}
use of org.eclipse.jgit.storage.file.FileRepositoryBuilder in project eclipse.platform.releng by eclipse.
the class LocalDiskRepositoryTest method createRepository.
/**
* Creates a new empty repository.
*
* @param bare
* true to create a bare repository; false to make a repository
* within its working directory
* @return the newly created repository, opened for access
* @throws IOException
* the repository could not be created in the temporary area
*/
private Repository createRepository(boolean bare) throws IOException {
File gitdir = createUniqueTestGitDir(bare);
FileRepositoryBuilder repositoryBuilder = new FileRepositoryBuilder();
repositoryBuilder.setMustExist(true);
repositoryBuilder.setGitDir(gitdir);
Repository db = repositoryBuilder.build();
Assert.assertFalse(gitdir.exists());
db.create();
toClose.add(db);
return db;
}
Aggregations