本文整理汇总了Java中org.eclipse.jgit.lib.RepositoryBuilder类的典型用法代码示例。如果您正苦于以下问题:Java RepositoryBuilder类的具体用法?Java RepositoryBuilder怎么用?Java RepositoryBuilder使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
RepositoryBuilder类属于org.eclipse.jgit.lib包,在下文中一共展示了RepositoryBuilder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: openRepository
import org.eclipse.jgit.lib.RepositoryBuilder; //导入依赖的package包/类
@Override
public Repository openRepository(String repositoryPath) throws Exception {
File folder = new File(repositoryPath);
Repository repository;
if (folder.exists()) {
RepositoryBuilder builder = new RepositoryBuilder();
repository = builder
.setGitDir(new File(folder, ".git"))
.readEnvironment()
.findGitDir()
.build();
} else {
throw new FileNotFoundException(repositoryPath);
}
return repository;
}
示例2: GitVersionControl
import org.eclipse.jgit.lib.RepositoryBuilder; //导入依赖的package包/类
public GitVersionControl(Path path) throws IOException {
try {
// Cribbed from Git.open, but with findGitDir rather than setGitDir
// and extracting the location.
FS fs = FS.DETECTED;
RepositoryCache.FileKey key = RepositoryCache.FileKey.lenient(path.toFile(), fs);
RepositoryBuilder builder = new RepositoryBuilder()
.setFS(fs)
.findGitDir(key.getFile())
.setMustExist(true);
repositoryRoot = Paths.get(builder.getGitDir().getAbsolutePath()).getParent();
repo = new Git(builder.build());
checkMergeDriver(repositoryRoot);
} catch (RuntimeException ex) {
throw new IOException(ex);
}
}
示例3: getLastCommitUuid
import org.eclipse.jgit.lib.RepositoryBuilder; //导入依赖的package包/类
/**
* @param gitConfigFolder e.g. /your/project/root/.git
*
* @return Returns last commit's UUID, "nocommit" if there are no commits and returns null if an exception occured
*/
public static String getLastCommitUuid( String gitConfigFolder ) throws MojoExecutionException {
try {
Repository repo =
new RepositoryBuilder().setGitDir( new File( gitConfigFolder ) ).readEnvironment().findGitDir()
.build();
RevWalk walk = new RevWalk( repo );
ObjectId head = repo.resolve( "HEAD" );
if ( head != null ) {
RevCommit lastCommit = walk.parseCommit( head );
return lastCommit.getId().getName();
}
else {
return "nocommit";
}
}
catch ( Exception e ) {
throw new MojoExecutionException( "Error trying to get the last git commit uuid", e );
}
}
示例4: isBareRepository
import org.eclipse.jgit.lib.RepositoryBuilder; //导入依赖的package包/类
/** {@inheritDoc} */
@Deprecated
public boolean isBareRepository(String GIT_DIR) throws GitException, InterruptedException {
Repository repo = null;
boolean isBare = false;
if (GIT_DIR == null) {
throw new GitException("Not a git repository"); // Compatible with CliGitAPIImpl
}
try {
if (isBlank(GIT_DIR) || !(new File(GIT_DIR)).isAbsolute()) {
if ((new File(workspace, ".git")).exists()) {
repo = getRepository();
} else {
repo = new RepositoryBuilder().setGitDir(workspace).build();
}
} else {
repo = new RepositoryBuilder().setGitDir(new File(GIT_DIR)).build();
}
isBare = repo.isBare();
} catch (IOException ioe) {
throw new GitException(ioe);
} finally {
if (repo != null) repo.close();
}
return isBare;
}
示例5: exist
import org.eclipse.jgit.lib.RepositoryBuilder; //导入依赖的package包/类
private static boolean exist(File repoDir) {
try {
RepositoryBuilder repositoryBuilder = new RepositoryBuilder().setGitDir(repoDir);
org.eclipse.jgit.lib.Repository repository = repositoryBuilder.build();
if (repository.getConfig() instanceof FileBasedConfig) {
return ((FileBasedConfig) repository.getConfig()).getFile().exists();
}
return repository.getDirectory().exists();
} catch (IOException e) {
throw new StorageException("failed to check if repository exists at " + repoDir, e);
}
}
示例6: openRepository
import org.eclipse.jgit.lib.RepositoryBuilder; //导入依赖的package包/类
public Repository openRepository(String repositoryPath) throws Exception {
File folder = new File(repositoryPath);
Repository repository;
if (folder.exists()) {
RepositoryBuilder builder = new RepositoryBuilder();
repository = builder
.setGitDir(new File(folder, ".git"))
.readEnvironment()
.findGitDir()
.build();
} else {
throw new FileNotFoundException(repositoryPath);
}
return repository;
}
示例7: open
import org.eclipse.jgit.lib.RepositoryBuilder; //导入依赖的package包/类
public static Repository open(File folder) throws IOException {
RepositoryBuilder builder = new RepositoryBuilder();
return builder
.setGitDir(new File(folder, ".git"))
.readEnvironment()
.findGitDir()
.build();
}
示例8: findRegisteredRepositories
import org.eclipse.jgit.lib.RepositoryBuilder; //导入依赖的package包/类
private List<Repository> findRegisteredRepositories() {
final RepositoryUtil util = Activator.getDefault().getRepositoryUtil();
final List<String> repositoryFolders = util.getConfiguredRepositories();
final List<Repository> repositories = new ArrayList<Repository>();
for (final String repositoryFolder : repositoryFolders) {
final File folder = new File(repositoryFolder);
if (!folder.exists() || !folder.isDirectory()) {
continue;
}
if (!folder.getName().equals(Constants.DOT_GIT) || !FileKey.isGitRepository(folder, FS.DETECTED)) {
continue;
}
final RepositoryBuilder rb = new RepositoryBuilder().setGitDir(folder).setMustExist(true);
try {
repositories.add(rb.build());
} catch (final Exception e) {
log.error("Error loading Git repository " + repositoryFolder, e); //$NON-NLS-1$
continue;
}
}
return repositories;
}
示例9: loadRegisteredRepositories
import org.eclipse.jgit.lib.RepositoryBuilder; //导入依赖的package包/类
private void loadRegisteredRepositories() {
repositoryMap = new TreeMap<String, Repository>();
final List<String> repositoryFolders = Activator.getDefault().getRepositoryUtil().getConfiguredRepositories();
for (final String repositoryFolder : repositoryFolders) {
final File folder = new File(repositoryFolder);
if (!folder.exists() || !folder.isDirectory()) {
continue;
}
if (!folder.getName().equals(Constants.DOT_GIT) || !FileKey.isGitRepository(folder, FS.DETECTED)) {
continue;
}
final RepositoryBuilder rb = new RepositoryBuilder().setGitDir(folder).setMustExist(true);
try {
final Repository repo = rb.build();
final StoredConfig repositoryConfig = repo.getConfig();
final Set<String> remotes = repositoryConfig.getSubsections(REMOTES_SECTION_NAME);
for (final String remoteName : remotes) {
final String remoteURL =
repositoryConfig.getString(REMOTES_SECTION_NAME, remoteName, URL_VALUE_NAME);
repositoryMap.put(remoteURL, repo);
}
} catch (final Exception e) {
log.error("Error loading local Git repository " + repositoryFolder, e); //$NON-NLS-1$
continue;
}
}
}
示例10: makePack
import org.eclipse.jgit.lib.RepositoryBuilder; //导入依赖的package包/类
/**
* Function used to treat pack object, it load the data from each object of
* the pack to create the original object when the object is recreate it
* store the object into the git object index
*
* @author Sylvain
*
* @param pathPack
* the path of the pack file
* @throws IOException
* @throws DataFormatException
*/
public static void makePack(String pathPack) throws IOException, DataFormatException {
String[] path = pathPack.split(osBarre + ".git" + osBarre);
RepositoryBuilder builder = new RepositoryBuilder();
builder.setMustExist(true);
builder.setGitDir(new File(path[0] + osBarre + ".git" + osBarre));
Repository repository = builder.build();
for (MutableEntry mutableEntry : new PackFile(new File(pathPack), 0)) {
GitObject obj = null;
String sha1 = mutableEntry.toObjectId().name();
ObjectId id = repository.resolve(sha1);
ObjectLoader loader = repository.open(id);
switch (loader.getType()) {
case Constants.OBJ_BLOB:
obj = new GitBlob(loader.getSize(), sha1, "", loader.getCachedBytes());
break;
case Constants.OBJ_COMMIT:
obj = new GitCommit(loader.getSize(), sha1, new String(loader.getCachedBytes()));
break;
case Constants.OBJ_TREE:
obj = new GitTree(loader.getSize(), sha1, loader.getBytes());
break;
case Constants.OBJ_TAG:
obj = new GitTag(loader.getSize(), sha1, new String(loader.getCachedBytes()));
break;
default:
break;
}
GitObjectsIndex.getInstance().put(mutableEntry.toObjectId().name(), obj);
}
}
示例11: revisionId
import org.eclipse.jgit.lib.RepositoryBuilder; //导入依赖的package包/类
@Override
public String revisionId(Path path) {
RepositoryBuilder builder = getVerifiedRepositoryBuilder(path);
try {
return builder.build().exactRef("HEAD").getObjectId().getName();
} catch (IOException e) {
throw new IllegalStateException("I/O error while getting revision ID for path: " + path, e);
}
}
示例12: getVerifiedRepositoryBuilder
import org.eclipse.jgit.lib.RepositoryBuilder; //导入依赖的package包/类
static RepositoryBuilder getVerifiedRepositoryBuilder(Path basedir) {
RepositoryBuilder builder = new RepositoryBuilder()
.findGitDir(basedir.toFile())
.setMustExist(true);
if (builder.getGitDir() == null) {
throw MessageException.of("Not inside a Git work tree: " + basedir);
}
return builder;
}
示例13: GitUtil
import org.eclipse.jgit.lib.RepositoryBuilder; //导入依赖的package包/类
public GitUtil(File f) {
try {
File workspace = findWorkspaceRoot(f);
if (workspace==null) {
throw new IllegalStateException("Does not appear to be a Git workspace: "+f.getCanonicalPath());
}
Repository r = new RepositoryBuilder().setWorkTree(findWorkspaceRoot(f)).build();
git = new Git(r);
}
catch (IOException e) {
throw new AstException(e);
}
}
示例14: load
import org.eclipse.jgit.lib.RepositoryBuilder; //导入依赖的package包/类
public Git load() throws IOException {
try (Repository repository = new RepositoryBuilder().findGitDir(this.sourceDirectory).build()) {
Git.Head head = getHead(repository);
String branch = getBranch(repository);
List<Git.Remote> remotes = getRemotes(repository);
return new Git(repository.getWorkTree(), head, branch, remotes);
}
}
示例15: getGitRemoteUrl
import org.eclipse.jgit.lib.RepositoryBuilder; //导入依赖的package包/类
/**
* @param gitConfigFolder e.g. /your/project/root/.git
*
* @return Returns git config remote.origin.url field of the repository located at gitConfigFolder
*/
public static String getGitRemoteUrl( String gitConfigFolder ) throws MojoExecutionException {
try {
Repository repo =
new RepositoryBuilder().setGitDir( new File( gitConfigFolder ) ).readEnvironment().findGitDir()
.build();
Config config = repo.getConfig();
return config.getString( "remote", "origin", "url" );
}
catch ( Exception e ) {
throw new MojoExecutionException( "Error trying to get remote origin url of git repository", e );
}
}