Search in sources :

Example 6 with Reference

use of com.gitblit.models.TicketModel.Reference in project gitblit by gitblit.

the class TicketReferenceTest method commitPatchsetSingleReference.

@Test
public void commitPatchsetSingleReference() throws Exception {
    setPatchsetAvailable(true);
    TicketModel a = ticketService.createTicket(repo, newTicket("commitPatchsetSingleReference-A"));
    TicketModel b = ticketService.createTicket(repo, newTicket("commitPatchsetSingleReference-B"));
    String branchName = String.format("ticket/%d", a.number);
    git.checkout().setCreateBranch(true).setName(branchName).call();
    final String message = String.format("commit for #%d - patchset single reference", b.number);
    final RevCommit revCommit1 = makeCommit(message);
    final String commit1Sha = revCommit1.name();
    assertPushSuccess(commit1Sha, branchName);
    a = ticketService.getTicket(repo, a.number);
    b = ticketService.getTicket(repo, b.number);
    assertFalse(a.hasReferences());
    assertTrue(b.hasReferences());
    List<Reference> cRefB = b.getReferences();
    assertNotNull(cRefB);
    assertEquals(1, cRefB.size());
    assertNull(cRefB.get(0).ticketId);
    assertEquals(commit1Sha, cRefB.get(0).hash);
}
Also used : Reference(com.gitblit.models.TicketModel.Reference) TicketModel(com.gitblit.models.TicketModel) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Test(org.junit.Test)

Example 7 with Reference

use of com.gitblit.models.TicketModel.Reference in project gitblit by gitblit.

the class TicketReferenceTest method commitMasterMultiReference.

@Test
public void commitMasterMultiReference() throws Exception {
    TicketModel a = ticketService.createTicket(repo, newTicket("commitMasterMultiReference-A"));
    TicketModel b = ticketService.createTicket(repo, newTicket("commitMasterMultiReference-B"));
    final String branchName = "master";
    git.checkout().setCreateBranch(false).setName(branchName).call();
    final String message = String.format("commit for #%d and #%d - multi reference", a.number, b.number);
    final RevCommit revCommit1 = makeCommit(message);
    final String commit1Sha = revCommit1.name();
    assertPushSuccess(commit1Sha, branchName);
    a = ticketService.getTicket(repo, a.number);
    b = ticketService.getTicket(repo, b.number);
    assertTrue(a.hasReferences());
    assertTrue(b.hasReferences());
    List<Reference> cRefA = a.getReferences();
    assertNotNull(cRefA);
    assertEquals(1, cRefA.size());
    assertNull(cRefA.get(0).ticketId);
    assertEquals(commit1Sha, cRefA.get(0).hash);
    List<Reference> cRefB = a.getReferences();
    assertNotNull(cRefB);
    assertEquals(1, cRefB.size());
    assertNull(cRefB.get(0).ticketId);
    assertEquals(commit1Sha, cRefB.get(0).hash);
}
Also used : Reference(com.gitblit.models.TicketModel.Reference) TicketModel(com.gitblit.models.TicketModel) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Test(org.junit.Test)

Example 8 with Reference

use of com.gitblit.models.TicketModel.Reference in project gitblit by gitblit.

the class TicketReferenceTest method commitTicketBranchDeletePostMergeReference.

@Test
public void commitTicketBranchDeletePostMergeReference() throws Exception {
    setPatchsetAvailable(false);
    TicketModel a = ticketService.createTicket(repo, newTicket("commitTicketBranchDeletePostMergeReference-A"));
    TicketModel b = ticketService.createTicket(repo, newTicket("commitTicketBranchDeletePostMergeReference-B"));
    TicketModel c = ticketService.createTicket(repo, newTicket("commitTicketBranchDeletePostMergeReference-C"));
    assertFalse(c.hasPatchsets());
    String branchName = String.format("ticket/%d", c.number);
    git.checkout().setCreateBranch(true).setName(branchName).call();
    String message = String.format("commit before amend for #%d and #%d", a.number, b.number);
    final RevCommit revCommit1 = makeCommit(message);
    final String commit1Sha = revCommit1.name();
    assertPushSuccess(commit1Sha, branchName);
    a = ticketService.getTicket(repo, a.number);
    b = ticketService.getTicket(repo, b.number);
    c = ticketService.getTicket(repo, c.number);
    assertTrue(a.hasReferences());
    assertTrue(b.hasReferences());
    assertFalse(c.hasReferences());
    List<Reference> cRefA = a.getReferences();
    assertNotNull(cRefA);
    assertEquals(1, cRefA.size());
    assertNull(cRefA.get(0).ticketId);
    assertEquals(commit1Sha, cRefA.get(0).hash);
    List<Reference> cRefB = b.getReferences();
    assertNotNull(cRefB);
    assertEquals(1, cRefB.size());
    assertNull(cRefB.get(0).ticketId);
    assertEquals(commit1Sha, cRefB.get(0).hash);
    git.checkout().setCreateBranch(false).setName("refs/heads/master").call();
    // merge the tip of the branch into master
    MergeResult mergeResult = git.merge().setFastForward(FastForwardMode.NO_FF).include(revCommit1.getId()).call();
    assertEquals(MergeResult.MergeStatus.MERGED, mergeResult.getMergeStatus());
    // push the merged master to the origin
    Iterable<PushResult> results = git.push().setCredentialsProvider(cp).setRemote("origin").call();
    for (PushResult result : results) {
        RemoteRefUpdate ref = result.getRemoteUpdate("refs/heads/master");
        assertEquals(Status.OK, ref.getStatus());
    }
    //As everything has been merged no references should be changed
    assertDeleteBranch(branchName);
    a = ticketService.getTicket(repo, a.number);
    b = ticketService.getTicket(repo, b.number);
    c = ticketService.getTicket(repo, c.number);
    assertTrue(a.hasReferences());
    assertTrue(b.hasReferences());
    assertFalse(c.hasReferences());
    cRefA = a.getReferences();
    assertNotNull(cRefA);
    assertEquals(1, cRefA.size());
    assertNull(cRefA.get(0).ticketId);
    assertEquals(commit1Sha, cRefA.get(0).hash);
    cRefB = b.getReferences();
    assertNotNull(cRefB);
    assertEquals(1, cRefB.size());
    assertNull(cRefB.get(0).ticketId);
    assertEquals(commit1Sha, cRefB.get(0).hash);
}
Also used : RemoteRefUpdate(org.eclipse.jgit.transport.RemoteRefUpdate) Reference(com.gitblit.models.TicketModel.Reference) MergeResult(org.eclipse.jgit.api.MergeResult) TicketModel(com.gitblit.models.TicketModel) PushResult(org.eclipse.jgit.transport.PushResult) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Test(org.junit.Test)

Example 9 with Reference

use of com.gitblit.models.TicketModel.Reference in project gitblit by gitblit.

the class TicketReferenceTest method commitTicketBranchSelfReference.

@Test
public void commitTicketBranchSelfReference() throws Exception {
    setPatchsetAvailable(false);
    TicketModel a = ticketService.createTicket(repo, newTicket("commitTicketBranchSelfReference-A"));
    String branchName = String.format("ticket/%d", a.number);
    git.checkout().setCreateBranch(true).setName(branchName).call();
    final String message = String.format("commit for #%d - patchset self reference", a.number);
    final RevCommit revCommit1 = makeCommit(message);
    final String commit1Sha = revCommit1.name();
    assertPushSuccess(commit1Sha, branchName);
    a = ticketService.getTicket(repo, a.number);
    assertTrue(a.hasReferences());
    List<Reference> cRefA = a.getReferences();
    assertNotNull(cRefA);
    assertEquals(1, cRefA.size());
    assertNull(cRefA.get(0).ticketId);
    assertEquals(commit1Sha, cRefA.get(0).hash);
}
Also used : Reference(com.gitblit.models.TicketModel.Reference) TicketModel(com.gitblit.models.TicketModel) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Test(org.junit.Test)

Example 10 with Reference

use of com.gitblit.models.TicketModel.Reference in project gitblit by gitblit.

the class TicketReferenceTest method commitTicketBranchMultiCommit.

@Test
public void commitTicketBranchMultiCommit() throws Exception {
    setPatchsetAvailable(false);
    TicketModel a = ticketService.createTicket(repo, newTicket("commitTicketBranchMultiCommit-A"));
    TicketModel b = ticketService.createTicket(repo, newTicket("commitTicketBranchMultiCommit-B"));
    String branchName = String.format("ticket/%d", a.number);
    git.checkout().setCreateBranch(true).setName(branchName).call();
    final String message1 = String.format("commit for #%d - patchset multi commit 1", b.number);
    final RevCommit revCommit1 = makeCommit(message1);
    final String commit1Sha = revCommit1.name();
    final String message2 = String.format("commit for #%d - patchset multi commit 2", b.number);
    final RevCommit revCommit2 = makeCommit(message2);
    final String commit2Sha = revCommit2.name();
    assertPushSuccess(commit2Sha, branchName);
    a = ticketService.getTicket(repo, a.number);
    b = ticketService.getTicket(repo, b.number);
    assertFalse(a.hasReferences());
    assertTrue(b.hasReferences());
    List<Reference> cRefB = b.getReferences();
    assertNotNull(cRefB);
    assertEquals(2, cRefB.size());
    assertNull(cRefB.get(0).ticketId);
    assertEquals(commit1Sha, cRefB.get(1).hash);
    assertEquals(commit2Sha, cRefB.get(0).hash);
}
Also used : Reference(com.gitblit.models.TicketModel.Reference) TicketModel(com.gitblit.models.TicketModel) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Test(org.junit.Test)

Aggregations

TicketModel (com.gitblit.models.TicketModel)16 Reference (com.gitblit.models.TicketModel.Reference)16 Test (org.junit.Test)16 RevCommit (org.eclipse.jgit.revwalk.RevCommit)13 Change (com.gitblit.models.TicketModel.Change)3 MergeResult (org.eclipse.jgit.api.MergeResult)1 PushResult (org.eclipse.jgit.transport.PushResult)1 RemoteRefUpdate (org.eclipse.jgit.transport.RemoteRefUpdate)1