use of org.eclipse.jgit.api.Status 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.api.Status in project camel by apache.
the class GitConsumerTest method commitConsumerTest.
@Test
public void commitConsumerTest() throws Exception {
// Init
MockEndpoint mockResultCommit = getMockEndpoint("mock:result-commit");
mockResultCommit.expectedMessageCount(2);
Git git = getGitTestRepository();
File gitDir = new File(gitLocalRepo, ".git");
assertEquals(gitDir.exists(), true);
File fileToAdd = new File(gitLocalRepo, filenameToAdd);
fileToAdd.createNewFile();
git.add().addFilepattern(filenameToAdd).call();
Status status = git.status().call();
assertTrue(status.getAdded().contains(filenameToAdd));
git.commit().setMessage(commitMessage).call();
File fileToAdd1 = new File(gitLocalRepo, filenameBranchToAdd);
fileToAdd1.createNewFile();
git.add().addFilepattern(filenameBranchToAdd).call();
status = git.status().call();
assertTrue(status.getAdded().contains(filenameBranchToAdd));
git.commit().setMessage("Test test Commit").call();
Iterable<RevCommit> logs = git.log().call();
validateGitLogs(git, "Test test Commit", commitMessage);
// Test
mockResultCommit.assertIsSatisfied();
// Check
Exchange ex1 = mockResultCommit.getExchanges().get(0);
Exchange ex2 = mockResultCommit.getExchanges().get(1);
assertEquals(commitMessage, ex2.getOut().getBody(RevCommit.class).getShortMessage());
assertEquals("Test test Commit", ex1.getOut().getBody(RevCommit.class).getShortMessage());
git.close();
}
use of org.eclipse.jgit.api.Status in project camel by apache.
the class GitConsumerTest method branchConsumerTest.
@Test
public void branchConsumerTest() throws Exception {
// Init
MockEndpoint mockResultBranch = getMockEndpoint("mock:result-branch");
mockResultBranch.expectedMessageCount(2);
Git git = getGitTestRepository();
File fileToAdd = new File(gitLocalRepo, filenameToAdd);
fileToAdd.createNewFile();
git.add().addFilepattern(filenameToAdd).call();
File gitDir = new File(gitLocalRepo, ".git");
assertEquals(gitDir.exists(), true);
Status status = git.status().call();
assertTrue(status.getAdded().contains(filenameToAdd));
git.commit().setMessage(commitMessage).call();
git.branchCreate().setName(branchTest).call();
List<Ref> ref = git.branchList().call();
boolean branchCreated = false;
for (Ref refInternal : ref) {
if (refInternal.getName().equals("refs/heads/" + branchTest)) {
branchCreated = true;
}
}
assertEquals(branchCreated, true);
// Test
mockResultBranch.assertIsSatisfied();
// Check
List<Exchange> exchanges = mockResultBranch.getExchanges();
assertEquals("refs/heads/master", exchanges.get(0).getOut().getBody(ObjectIdRef.Unpeeled.class).getName());
assertEquals("refs/heads/" + branchTest, exchanges.get(1).getOut().getBody(ObjectIdRef.Unpeeled.class).getName());
git.close();
}
use of org.eclipse.jgit.api.Status in project camel by apache.
the class GitProducerTest method commitAllDifferentBranchTest.
@Test
public void commitAllDifferentBranchTest() throws Exception {
// Init
Git git = getGitTestRepository();
File gitDir = new File(gitLocalRepo, ".git");
assertEquals(gitDir.exists(), true);
File fileToAdd = new File(gitLocalRepo, filenameToAdd);
fileToAdd.createNewFile();
git.add().addFilepattern(filenameToAdd).call();
Status status = git.status().call();
assertTrue(status.getAdded().contains(filenameToAdd));
git.commit().setMessage(commitMessage).call();
validateGitLogs(git, commitMessage);
git.checkout().setCreateBranch(true).setName(branchTest).setUpstreamMode(SetupUpstreamMode.SET_UPSTREAM).call();
File fileToAdd1 = new File(gitLocalRepo, filenameBranchToAdd);
fileToAdd1.createNewFile();
// Test camel-git add and commit (different branches)
template.send("direct:add-on-branch", new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
exchange.getIn().setHeader(GitConstants.GIT_FILE_NAME, filenameBranchToAdd);
}
});
template.send("direct:commit-all-branch", new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
exchange.getIn().setHeader(GitConstants.GIT_COMMIT_MESSAGE, commitMessageAll);
}
});
// Check
validateGitLogs(git, commitMessageAll, commitMessage);
git.close();
}
use of org.eclipse.jgit.api.Status in project camel by apache.
the class GitProducerTest method commitTestAllowEmptyFalse.
@Test(expected = CamelExecutionException.class)
public void commitTestAllowEmptyFalse() throws Exception {
// Init
Git git = getGitTestRepository();
File gitDir = new File(gitLocalRepo, ".git");
assertEquals(gitDir.exists(), true);
File fileToAdd = new File(gitLocalRepo, filenameToAdd);
fileToAdd.createNewFile();
git.add().addFilepattern(filenameToAdd).call();
Status status = git.status().call();
assertTrue(status.getAdded().contains(filenameToAdd));
git.commit().setMessage(commitMessage).call();
// Test camel-git commit (with allowEmpty set to false)
Map<String, Object> headers = new HashMap<>();
headers.put(GitConstants.GIT_COMMIT_MESSAGE, commitMessage);
template.requestBodyAndHeaders("direct:commit-not-allow-empty", "", headers);
// Check : An exception should have been raised
}
Aggregations