Search in sources :

Example 16 with RefSpec

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());
}
Also used : RefSpec(org.eclipse.jgit.transport.RefSpec) ChangeApi(com.google.gerrit.extensions.api.changes.ChangeApi) CherryPickInput(com.google.gerrit.extensions.api.changes.CherryPickInput) BranchInput(com.google.gerrit.extensions.api.projects.BranchInput) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Test(org.junit.Test)

Example 17 with RefSpec

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");
}
Also used : RefSpec(org.eclipse.jgit.transport.RefSpec) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 18 with RefSpec

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");
}
Also used : RefSpec(org.eclipse.jgit.transport.RefSpec) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 19 with RefSpec

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(), "");
}
Also used : RefSpec(org.eclipse.jgit.transport.RefSpec) ObjectId(org.eclipse.jgit.lib.ObjectId) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 20 with RefSpec

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");
}
Also used : RefSpec(org.eclipse.jgit.transport.RefSpec) ChangeApi(com.google.gerrit.extensions.api.changes.ChangeApi) ObjectId(org.eclipse.jgit.lib.ObjectId) CherryPickInput(com.google.gerrit.extensions.api.changes.CherryPickInput) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Aggregations

RefSpec (org.eclipse.jgit.transport.RefSpec)46 Test (org.junit.Test)17 RevCommit (org.eclipse.jgit.revwalk.RevCommit)15 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)12 IOException (java.io.IOException)11 ObjectId (org.eclipse.jgit.lib.ObjectId)11 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)9 Git (org.eclipse.jgit.api.Git)8 PushCommand (org.eclipse.jgit.api.PushCommand)8 File (java.io.File)7 PushResult (org.eclipse.jgit.transport.PushResult)7 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)6 UsernamePasswordCredentialsProvider (org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider)6 AppServicePlan (com.microsoft.azure.management.appservice.AppServicePlan)5 PublishingProfile (com.microsoft.azure.management.appservice.PublishingProfile)5 ArrayList (java.util.ArrayList)5 FetchCommand (org.eclipse.jgit.api.FetchCommand)5 ChangeApi (com.google.gerrit.extensions.api.changes.ChangeApi)4 CherryPickInput (com.google.gerrit.extensions.api.changes.CherryPickInput)4 GitException (org.eclipse.che.api.git.exception.GitException)4