use of org.eclipse.jgit.storage.file.FileRepositoryBuilder in project bazel by bazelbuild.
the class GitCloner method isUpToDate.
private static boolean isUpToDate(GitRepositoryDescriptor descriptor) {
// Initializing/checking status of/etc submodules cleanly is hard, so don't try for now.
if (descriptor.initSubmodules) {
return false;
}
Repository repository = null;
try {
repository = new FileRepositoryBuilder().setGitDir(descriptor.directory.getChild(Constants.DOT_GIT).getPathFile()).setMustExist(true).build();
ObjectId head = repository.resolve(Constants.HEAD);
ObjectId checkout = repository.resolve(descriptor.checkout);
if (head != null && checkout != null && head.equals(checkout)) {
Status status = Git.wrap(repository).status().call();
if (!status.hasUncommittedChanges()) {
// new_git_repository puts (only) BUILD and WORKSPACE, and
// git_repository doesn't add any files.
Set<String> untracked = status.getUntracked();
if (untracked.isEmpty() || (untracked.size() == 2 && untracked.contains("BUILD") && untracked.contains("WORKSPACE"))) {
return true;
}
}
}
} catch (GitAPIException | IOException e) {
// Any exceptions here, we'll just blow it away and try cloning fresh.
// The fresh clone avoids any weirdness due to what's there and has nicer
// error reporting.
} finally {
if (repository != null) {
repository.close();
}
}
return false;
}
use of org.eclipse.jgit.storage.file.FileRepositoryBuilder in project gitblit by gitblit.
the class PushLogTest method testPushLog.
@Test
public void testPushLog() throws IOException {
String name = "~james/helloworld.git";
File gitDir = FileKey.resolve(new File(GitBlitSuite.REPOSITORIES, name), FS.DETECTED);
Repository repository = new FileRepositoryBuilder().setGitDir(gitDir).build();
List<RefLogEntry> pushes = RefLogUtils.getRefLog(name, repository);
GitBlitSuite.close(repository);
}
use of org.eclipse.jgit.storage.file.FileRepositoryBuilder in project camel by apache.
the class AbstractGitConsumer method getLocalRepository.
private Repository getLocalRepository() throws IOException {
FileRepositoryBuilder builder = new FileRepositoryBuilder();
Repository repo = null;
try {
repo = // scan environment GIT_* variables
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 camel by apache.
the class GitTestSupport method getTestRepository.
protected Repository getTestRepository() throws IOException, IllegalStateException, GitAPIException {
File gitRepo = new File(gitLocalRepo, ".git");
Git.init().setDirectory(new File(gitLocalRepo, "")).setBare(false).call();
// now open the resulting repository with a FileRepositoryBuilder
FileRepositoryBuilder builder = new FileRepositoryBuilder();
Repository repo = // scan
builder.setGitDir(gitRepo).readEnvironment().findGitDir().build();
return repo;
}
use of org.eclipse.jgit.storage.file.FileRepositoryBuilder in project Corgi by kevinYin.
the class JGitTest method testGetVersion.
@Test
public void testGetVersion() throws Exception {
Repository existingRepo = new FileRepositoryBuilder().setGitDir(new File("/Users/kevin/beiliao/gitlab/platform-parent/.git")).build();
Git git = new Git(existingRepo);
CredentialsProvider cp = new UsernamePasswordCredentialsProvider("K-Priest", "kevin711");
Collection<Ref> refs = git.lsRemote().setCredentialsProvider(cp).setRemote("origin").call();
for (Ref ref : refs) {
System.out.println(ref.getObjectId().getName());
}
}
Aggregations