use of org.eclipse.jgit.transport.RefSpec in project gerrit by GerritCodeReview.
the class SubmitByMergeIfNecessaryIT method gerritWorkflow.
@Test
public void gerritWorkflow() throws Exception {
RevCommit initialHead = getRemoteHead();
// We'll setup a master and a stable branch.
// Then we create a change to be applied to master, which is
// then cherry picked back to stable. The stable branch will
// be merged up into master again.
gApi.projects().name(project.get()).branch("stable").create(new BranchInput());
// Push a change to master
PushOneCommit push = pushFactory.create(db, user.getIdent(), testRepo, "small fix", "a.txt", "2");
PushOneCommit.Result change = push.to("refs/for/master");
submit(change.getChangeId());
RevCommit headAfterFirstSubmit = getRemoteLog(project, "master").get(0);
assertThat(headAfterFirstSubmit.getShortMessage()).isEqualTo(change.getCommit().getShortMessage());
// Now cherry pick to stable
CherryPickInput in = new CherryPickInput();
in.destination = "stable";
in.message = "This goes to stable as well\n" + headAfterFirstSubmit.getFullMessage();
ChangeApi orig = gApi.changes().id(change.getChangeId());
String cherryId = orig.current().cherryPick(in).id();
gApi.changes().id(cherryId).current().review(ReviewInput.approve());
gApi.changes().id(cherryId).current().submit();
// Create the merge locally
RevCommit stable = getRemoteHead(project, "stable");
RevCommit master = getRemoteHead(project, "master");
testRepo.git().fetch().call();
testRepo.git().branchCreate().setName("stable").setStartPoint(stable).call();
testRepo.git().branchCreate().setName("master").setStartPoint(master).call();
RevCommit merge = testRepo.commit().parent(master).parent(stable).message("Merge stable into master").insertChangeId().create();
testRepo.branch("refs/heads/master").update(merge);
testRepo.git().push().setRefSpecs(new RefSpec("refs/heads/master:refs/for/master")).call();
String changeId = GitUtil.getChangeId(testRepo, merge).get();
approve(changeId);
submit(changeId);
RevCommit headAfterSecondSubmit = getRemoteLog(project, "master").get(0);
assertThat(headAfterSecondSubmit.getShortMessage()).isEqualTo(merge.getShortMessage());
assertRefUpdatedEvents(initialHead, headAfterFirstSubmit, headAfterFirstSubmit, headAfterSecondSubmit);
assertChangeMergedEvents(change.getChangeId(), headAfterFirstSubmit.name(), changeId, headAfterSecondSubmit.name());
}
use of org.eclipse.jgit.transport.RefSpec in project gerrit by GerritCodeReview.
the class CheckMergeabilityIT method checkMergeableCommit.
@Test
public void checkMergeableCommit() throws Exception {
RevCommit initialHead = getRemoteHead();
testRepo.branch("HEAD").commit().insertChangeId().message("some change in a").add("a.txt", "a contents ").create();
testRepo.git().push().setRemote("origin").setRefSpecs(new RefSpec("HEAD:refs/heads/master")).call();
testRepo.reset(initialHead);
testRepo.branch("HEAD").commit().insertChangeId().message("some change in b").add("b.txt", "b contents ").create();
testRepo.git().push().setRemote("origin").setRefSpecs(new RefSpec("HEAD:refs/heads/test")).call();
assertMergeable("master", "test", "recursive");
}
use of org.eclipse.jgit.transport.RefSpec in project gerrit by GerritCodeReview.
the class CheckMergeabilityIT method checkUnMergeableCommit.
@Test
public void checkUnMergeableCommit() throws Exception {
RevCommit initialHead = getRemoteHead();
testRepo.branch("HEAD").commit().insertChangeId().message("some change in a").add("a.txt", "a contents ").create();
testRepo.git().push().setRemote("origin").setRefSpecs(new RefSpec("HEAD:refs/heads/master")).call();
testRepo.reset(initialHead);
testRepo.branch("HEAD").commit().insertChangeId().message("some change in a too").add("a.txt", "a contents too").create();
testRepo.git().push().setRemote("origin").setRefSpecs(new RefSpec("HEAD:refs/heads/test")).call();
assertUnMergeable("master", "test", "recursive", "a.txt");
}
use of org.eclipse.jgit.transport.RefSpec in project gerrit by GerritCodeReview.
the class CheckMergeabilityIT method checkAlreadyMergedCommit.
@Test
public void checkAlreadyMergedCommit() throws Exception {
ObjectId c0 = testRepo.branch("HEAD").commit().insertChangeId().message("first commit").add("a.txt", "a contents ").create();
testRepo.git().push().setRemote("origin").setRefSpecs(new RefSpec("HEAD:refs/heads/master")).call();
testRepo.branch("HEAD").commit().insertChangeId().message("second commit").add("b.txt", "b contents ").create();
testRepo.git().push().setRemote("origin").setRefSpecs(new RefSpec("HEAD:refs/heads/master")).call();
assertCommitMerged("master", c0.getName(), "");
}
use of org.eclipse.jgit.transport.RefSpec in project gerrit by GerritCodeReview.
the class CheckMergeabilityIT method checkContentMergedCommit.
@Test
public void checkContentMergedCommit() throws Exception {
testRepo.branch("HEAD").commit().insertChangeId().message("first commit").add("a.txt", "a contents ").create();
testRepo.git().push().setRemote("origin").setRefSpecs(new RefSpec("HEAD:refs/heads/master")).call();
// create a change, and cherrypick into master
PushOneCommit.Result cId = createChange();
RevCommit commitId = cId.getCommit();
CherryPickInput cpi = new CherryPickInput();
cpi.destination = "master";
cpi.message = "cherry pick the commit";
ChangeApi orig = gApi.changes().id(cId.getChangeId());
ChangeApi cherry = orig.current().cherryPick(cpi);
cherry.current().review(ReviewInput.approve());
cherry.current().submit();
ObjectId remoteId = getRemoteHead();
assertThat(remoteId).isNotEqualTo(commitId);
assertContentMerged("master", commitId.getName(), "recursive");
}
Aggregations