use of org.eclipse.jgit.revwalk.RevCommit in project camel by apache.
the class GitProducerTest method cherryPickTest.
@Test
public void cherryPickTest() throws Exception {
// Init
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> branches = git.branchList().call();
Boolean branchExists = false;
for (Ref reference : branches) {
if (("refs/heads/" + branchTest).equals(reference.getName())) {
branchExists = true;
}
}
assertTrue(branchExists);
String fileToAdd1Name = "filetest1test.txt";
File fileToAdd1 = new File(gitLocalRepo, fileToAdd1Name);
fileToAdd1.createNewFile();
git.add().addFilepattern(fileToAdd1Name).call();
status = git.status().call();
assertTrue(status.getAdded().contains(fileToAdd1Name));
git.commit().setMessage("Test second commit").call();
Iterable<RevCommit> logs = git.log().call();
validateGitLogs(git, "Test second commit", commitMessage);
String id = logs.iterator().next().getName();
// Test camel-git cherry-pick
template.sendBodyAndHeader("direct:cherrypick", "", GitConstants.GIT_COMMIT_ID, id);
// Check
validateGitLogs(git, "Test second commit", commitMessage);
git.close();
}
use of org.eclipse.jgit.revwalk.RevCommit in project camel by apache.
the class GitProducerTest method logBranchTest.
@Test
public void logBranchTest() throws Exception {
// Init
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);
File fileToAddDifferent = new File(gitLocalRepo, filenameBranchToAdd);
fileToAddDifferent.createNewFile();
git.add().addFilepattern(filenameBranchToAdd).call();
git.commit().setMessage(commitMessageAll).call();
// Test camel-git log (with branches)
Iterable<RevCommit> revCommits = template.requestBody("direct:log-branch", "", Iterable.class);
// Check
Iterator<RevCommit> gitLogs = git.log().call().iterator();
for (RevCommit rev : revCommits) {
RevCommit gitRevCommit = gitLogs.next();
assertEquals(gitRevCommit.getName(), rev.getName());
assertEquals(gitRevCommit.getShortMessage(), rev.getShortMessage());
}
git.close();
}
use of org.eclipse.jgit.revwalk.RevCommit in project gocd by gocd.
the class ConfigRepository method commitCountOnMaster.
public Long commitCountOnMaster() throws GitAPIException, IncorrectObjectTypeException, MissingObjectException {
// not inside a doLocked/synchronized block because we don't want to block the server status service.
// we do a `git branch` because we switch branches as part of normal git operations,
// and we don't care about number of commits on those branches.
List<Ref> branches = git.branchList().call();
for (Ref branch : branches) {
if (branch.getName().equals("refs/heads/master")) {
Iterable<RevCommit> commits = git.log().add(branch.getObjectId()).call();
long count = 0;
for (RevCommit commit : commits) {
count++;
}
return count;
}
}
return Long.valueOf(-1);
}
use of org.eclipse.jgit.revwalk.RevCommit in project kie-wb-common by kiegroup.
the class DefaultMavenCompilerTest method buildWithAllDecoratorsTest.
//
@Test
public void buildWithAllDecoratorsTest() throws Exception {
String alternateSettingsAbsPath = new File("src/test/settings.xml").getAbsolutePath();
AFCompiler compiler = MavenCompilerFactory.getCompiler(Decorator.JGIT_BEFORE_AND_LOG_AFTER);
String MASTER_BRANCH = "master";
// Setup origin in memory
final URI originRepo = URI.create("git://repo");
final JGitFileSystem origin = (JGitFileSystem) ioService.newFileSystem(originRepo, new HashMap<String, Object>() {
{
put("init", Boolean.TRUE);
put("internal", Boolean.TRUE);
put("listMode", "ALL");
}
});
assertNotNull(origin);
ioService.startBatch(origin);
ioService.write(origin.getPath("/dummy/pom.xml"), new String(java.nio.file.Files.readAllBytes(new File("target/test-classes/kjar-2-single-resources/pom.xml").toPath())));
ioService.write(origin.getPath("/dummy/src/main/java/org/kie/maven/plugin/test/Person.java"), new String(java.nio.file.Files.readAllBytes(new File("target/test-classes/kjar-2-single-resources/src/main/java/org/kie/maven/plugin/test/Person.java").toPath())));
ioService.write(origin.getPath("/dummy/src/main/resources/AllResourceTypes/simple-rules.drl"), new String(java.nio.file.Files.readAllBytes(new File("target/test-classes/kjar-2-single-resources/src/main/resources/AllResourceTypes/simple-rules.drl").toPath())));
ioService.write(origin.getPath("/dummy/src/main/resources/META-INF/kmodule.xml"), new String(java.nio.file.Files.readAllBytes(new File("target/test-classes/kjar-2-single-resources/src/main/resources/META-INF/kmodule.xml").toPath())));
ioService.endBatch();
RevCommit lastCommit = origin.getGit().resolveRevCommit(origin.getGit().getRef(MASTER_BRANCH).getObjectId());
assertNotNull(lastCommit);
// clone into a regularfs
Path tmpRootCloned = Files.createTempDirectory("cloned");
Path tmpCloned = Files.createDirectories(Paths.get(tmpRootCloned.toString(), ".clone.git"));
final Git cloned = Git.cloneRepository().setURI("git://localhost:9418/repo").setBare(false).setDirectory(tmpCloned.toFile()).call();
assertNotNull(cloned);
WorkspaceCompilationInfo info = new WorkspaceCompilationInfo(Paths.get(tmpCloned + "/dummy"));
CompilationRequest req = new DefaultCompilationRequest(mavenRepo.toAbsolutePath().toString(), info, new String[] { MavenCLIArgs.COMPILE, MavenCLIArgs.ALTERNATE_USER_SETTINGS + alternateSettingsAbsPath }, new HashMap<>(), Boolean.TRUE);
CompilationResponse res = compiler.compileSync(req);
if (res.getMavenOutput().isPresent() && !res.isSuccessful()) {
TestUtil.writeMavenOutputIntoTargetFolder(res.getMavenOutput().get(), "KieDefaultMavenCompilerOnInMemoryFSTest.buildWithAllDecoratorsTest");
}
assertTrue(res.getMavenOutput().isPresent());
assertTrue(res.isSuccessful());
lastCommit = origin.getGit().resolveRevCommit(origin.getGit().getRef(MASTER_BRANCH).getObjectId());
assertNotNull(lastCommit);
// change one file and commit on the origin repo
ioService.write(origin.getPath("/dummy/src/main/java/org/kie/maven/plugin/test/Person.java"), new String(java.nio.file.Files.readAllBytes(new File("src/test/projects/Person.java").toPath())));
RevCommit commitBefore = origin.getGit().resolveRevCommit(origin.getGit().getRef(MASTER_BRANCH).getObjectId());
assertNotNull(commitBefore);
assertFalse(lastCommit.getId().toString().equals(commitBefore.getId().toString()));
// recompile
res = compiler.compileSync(req);
if (res.getMavenOutput().isPresent() && !res.isSuccessful()) {
TestUtil.writeMavenOutputIntoTargetFolder(res.getMavenOutput().get(), "KieDefaultMavenCompilerOnInMemoryFSTest.buildWithAllDecoratorsTest");
}
assertTrue(res.isSuccessful());
assertTrue(res.getMavenOutput().isPresent());
TestUtil.rm(tmpRootCloned.toFile());
}
use of org.eclipse.jgit.revwalk.RevCommit in project kie-wb-common by kiegroup.
the class DefaultMavenCompilerTest method buildWithJGitDecoratorTest.
@Test
public void buildWithJGitDecoratorTest() throws Exception {
AFCompiler compiler = MavenCompilerFactory.getCompiler(Decorator.JGIT_BEFORE);
String MASTER_BRANCH = "master";
// Setup origin in memory
final URI originRepo = URI.create("git://repo");
final JGitFileSystem origin = (JGitFileSystem) ioService.newFileSystem(originRepo, new HashMap<String, Object>() {
{
put("init", Boolean.TRUE);
put("internal", Boolean.TRUE);
put("listMode", "ALL");
}
});
assertNotNull(origin);
ioService.startBatch(origin);
ioService.write(origin.getPath("/dummy/pom.xml"), new String(java.nio.file.Files.readAllBytes(new File("src/test/projects/dummy_multimodule_untouched/pom.xml").toPath())));
ioService.write(origin.getPath("/dummy/dummyA/src/main/java/dummy/DummyA.java"), new String(java.nio.file.Files.readAllBytes(new File("src/test/projects/dummy_multimodule_untouched/dummyA/src/main/java/dummy/DummyA.java").toPath())));
ioService.write(origin.getPath("/dummy/dummyB/src/main/java/dummy/DummyB.java"), new String(java.nio.file.Files.readAllBytes(new File("src/test/projects/dummy_multimodule_untouched/dummyB/src/main/java/dummy/DummyB.java").toPath())));
ioService.write(origin.getPath("/dummy/dummyA/pom.xml"), new String(java.nio.file.Files.readAllBytes(new File("src/test/projects/dummy_multimodule_untouched/dummyA/pom.xml").toPath())));
ioService.write(origin.getPath("/dummy/dummyB/pom.xml"), new String(java.nio.file.Files.readAllBytes(new File("src/test/projects/dummy_multimodule_untouched/dummyB/pom.xml").toPath())));
ioService.endBatch();
RevCommit lastCommit = origin.getGit().resolveRevCommit(origin.getGit().getRef(MASTER_BRANCH).getObjectId());
assertNotNull(lastCommit);
// @TODO refactor and use only one between the URI or Git
// @TODO find a way to resolve the problem of the prjname inside .git folder
WorkspaceCompilationInfo info = new WorkspaceCompilationInfo(origin.getPath("/dummy/"));
CompilationRequest req = new DefaultCompilationRequest(mavenRepo.toAbsolutePath().toString(), info, new String[] { MavenCLIArgs.CLEAN, MavenCLIArgs.COMPILE }, new HashMap<>(), Boolean.FALSE);
CompilationResponse res = compiler.compileSync(req);
if (res.getMavenOutput().isPresent() && !res.isSuccessful()) {
TestUtil.writeMavenOutputIntoTargetFolder(res.getMavenOutput().get(), "KieDefaultMavenCompilerOnInMemoryFSTest.buildWithJGitDecoratorTest");
}
assertTrue(res.isSuccessful());
lastCommit = origin.getGit().resolveRevCommit(origin.getGit().getRef(MASTER_BRANCH).getObjectId());
;
assertNotNull(lastCommit);
ioService.write(origin.getPath("/dummy/dummyA/src/main/java/dummy/DummyA.java"), new String(java.nio.file.Files.readAllBytes(new File("src/test/projects/DummyA.java").toPath())));
RevCommit commitBefore = origin.getGit().resolveRevCommit(origin.getGit().getRef(MASTER_BRANCH).getObjectId());
assertNotNull(commitBefore);
assertFalse(lastCommit.getId().toString().equals(commitBefore.getId().toString()));
// recompile
res = compiler.compileSync(req);
// assert commits
assertTrue(res.isSuccessful());
}
Aggregations