Search in sources :

Example 41 with RefSpec

use of org.eclipse.jgit.transport.RefSpec in project gerrit by GerritCodeReview.

the class AbstractSubmoduleSubscription method pushChangeTo.

protected ObjectId pushChangeTo(TestRepository<?> repo, String ref, String file, String content, String message, String topic) throws Exception {
    ObjectId ret = repo.branch("HEAD").commit().insertChangeId().message(message).add(file, content).create();
    String pushedRef = ref;
    if (!topic.isEmpty()) {
        pushedRef += "/" + name(topic);
    }
    String refspec = "HEAD:" + pushedRef;
    Iterable<PushResult> res = repo.git().push().setRemote("origin").setRefSpecs(new RefSpec(refspec)).call();
    RemoteRefUpdate u = Iterables.getOnlyElement(res).getRemoteUpdate(pushedRef);
    assertThat(u).isNotNull();
    assertThat(u.getStatus()).isEqualTo(Status.OK);
    assertThat(u.getNewObjectId()).isEqualTo(ret);
    return ret;
}
Also used : RemoteRefUpdate(org.eclipse.jgit.transport.RemoteRefUpdate) RefSpec(org.eclipse.jgit.transport.RefSpec) ObjectId(org.eclipse.jgit.lib.ObjectId) PushResult(org.eclipse.jgit.transport.PushResult)

Example 42 with RefSpec

use of org.eclipse.jgit.transport.RefSpec in project gerrit by GerritCodeReview.

the class CreateChangeIT method alreadyMerged.

@Test
public void alreadyMerged() 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();
    ChangeInput in = newMergeChangeInput("master", c0.getName(), "");
    assertCreateFails(in, ChangeAlreadyMergedException.class, "'" + c0.getName() + "' has already been merged");
}
Also used : RefSpec(org.eclipse.jgit.transport.RefSpec) ObjectId(org.eclipse.jgit.lib.ObjectId) ChangeInput(com.google.gerrit.extensions.common.ChangeInput) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 43 with RefSpec

use of org.eclipse.jgit.transport.RefSpec in project gerrit by GerritCodeReview.

the class CreateChangeIT method onlyContentMerged.

@Test
public void onlyContentMerged() 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);
    ChangeInput in = newMergeChangeInput("master", commitId.getName(), "");
    assertCreateSucceeds(in);
}
Also used : Result(com.google.gerrit.acceptance.PushOneCommit.Result) 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) ChangeInput(com.google.gerrit.extensions.common.ChangeInput) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) RevCommit(org.eclipse.jgit.revwalk.RevCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 44 with RefSpec

use of org.eclipse.jgit.transport.RefSpec in project gerrit by GerritCodeReview.

the class SubmitByMergeIfNecessaryIT method openChangeForTargetBranchPreventsMerge.

@Test
public void openChangeForTargetBranchPreventsMerge() throws Exception {
    gApi.projects().name(project.get()).branch("stable").create(new BranchInput());
    // Propose a change for master, but leave it open for master!
    PushOneCommit change = pushFactory.create(db, user.getIdent(), testRepo, "small fix", "a.txt", "2");
    PushOneCommit.Result change2result = change.to("refs/for/master");
    // Now cherry pick to stable
    CherryPickInput in = new CherryPickInput();
    in.destination = "stable";
    in.message = "it goes to stable branch";
    ChangeApi orig = gApi.changes().id(change2result.getChangeId());
    ChangeApi cherry = orig.current().cherryPick(in);
    cherry.current().review(ReviewInput.approve());
    cherry.current().submit();
    // Create a commit locally
    testRepo.git().fetch().setRefSpecs(new RefSpec("refs/heads/stable")).call();
    PushOneCommit.Result change3 = createChange(testRepo, "stable", "test", "a.txt", "3", "");
    submitWithConflict(change3.getChangeId(), "Failed to submit 1 change due to the following problems:\n" + "Change " + change3.getPatchSetId().getParentKey().get() + ": depends on change that was not submitted");
    assertRefUpdatedEvents();
    assertChangeMergedEvents();
}
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) Test(org.junit.Test)

Example 45 with RefSpec

use of org.eclipse.jgit.transport.RefSpec in project gerrit by GerritCodeReview.

the class CheckMergeabilityIT method checkOursMergeStrategy.

@Test
public void checkOursMergeStrategy() 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();
    assertMergeable("master", "test", "ours");
}
Also used : RefSpec(org.eclipse.jgit.transport.RefSpec) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Aggregations

RefSpec (org.eclipse.jgit.transport.RefSpec)49 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 PushCommand (org.eclipse.jgit.api.PushCommand)10 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)9 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)9 PushResult (org.eclipse.jgit.transport.PushResult)9 Git (org.eclipse.jgit.api.Git)8 File (java.io.File)7 FetchCommand (org.eclipse.jgit.api.FetchCommand)6 RemoteRefUpdate (org.eclipse.jgit.transport.RemoteRefUpdate)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 ChangeApi (com.google.gerrit.extensions.api.changes.ChangeApi)4 CherryPickInput (com.google.gerrit.extensions.api.changes.CherryPickInput)4