Search in sources :

Example 96 with RefUpdate

use of org.eclipse.jgit.lib.RefUpdate in project gerrit by GerritCodeReview.

the class RefOperationValidationIT method rejectRefUpdateNonFastForward.

@Test
public void rejectRefUpdateNonFastForward() throws Exception {
    gApi.projects().name(project.get()).branch(TEST_REF).create(new BranchInput());
    try (Registration registration = testValidator(UPDATE_NONFASTFORWARD)) {
        ObjectId initial = repo().exactRef(HEAD).getLeaf().getObjectId();
        grant(Permission.PUSH);
        PushOneCommit push1 = pushFactory.create(admin.newIdent(), testRepo, "change1", "a.txt", "content");
        PushOneCommit.Result r1 = push1.to(TEST_REF);
        r1.assertOkStatus();
        // Reset HEAD to initial so the new change is a non-fast forward
        RefUpdate ru = repo().updateRef(HEAD);
        ru.setNewObjectId(initial);
        assertThat(ru.forceUpdate()).isEqualTo(RefUpdate.Result.FORCED);
        PushOneCommit push2 = pushFactory.create(admin.newIdent(), testRepo, "change2", "b.txt", "content");
        push2.setForce(true);
        PushOneCommit.Result r2 = push2.to(TEST_REF);
        r2.assertErrorStatus(UPDATE_NONFASTFORWARD.name());
    }
}
Also used : ObjectId(org.eclipse.jgit.lib.ObjectId) Registration(com.google.gerrit.acceptance.ExtensionRegistry.Registration) BranchInput(com.google.gerrit.extensions.api.projects.BranchInput) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) RefUpdate(org.eclipse.jgit.lib.RefUpdate) RemoteRefUpdate(org.eclipse.jgit.transport.RemoteRefUpdate) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 97 with RefUpdate

use of org.eclipse.jgit.lib.RefUpdate in project gerrit by GerritCodeReview.

the class RefAdvertisementIT method uploadPackTagUpdatedReachableVisible.

// first  ls-remote: rcBranch (c2 branch)               <- newcommit1 (updated-tag)
// second ls-remote: rcBranch (c2 branch updated-tag)
@Test
public void uploadPackTagUpdatedReachableVisible() throws Exception {
    projectOperations.project(project).forUpdate().add(allow(Permission.READ).ref("refs/heads/branch").group(REGISTERED_USERS)).add(allow(Permission.PUSH).ref("refs/tags/*").group(REGISTERED_USERS)).update();
    requestScopeOperations.setApiUser(user.id());
    try (Repository repo = repoManager.openRepository(project)) {
        // rcBranch (c2 branch) <- newcommit1 (updated-tag)
        PushOneCommit.Result r = pushFactory.create(admin.newIdent(), testRepo).setParent(rcBranch).to("refs/tags/updated-tag");
        r.assertOkStatus();
        RevCommit tagRc = r.getCommit();
        assertUploadPackRefs(psRef2, metaRef2, psRef4, metaRef4, "refs/heads/branch", "refs/tags/branch-tag", "refs/tags/master-tag");
        // rcBranch (c2 branch updated-tag)
        RefUpdate btu = repo.updateRef("refs/tags/updated-tag");
        btu.setExpectedOldObjectId(tagRc);
        btu.setNewObjectId(rcBranch);
        btu.setForceUpdate(true);
        assertThat(btu.update()).isEqualTo(RefUpdate.Result.FORCED);
    }
    assertUploadPackRefs(psRef2, metaRef2, psRef4, metaRef4, "refs/heads/branch", "refs/tags/branch-tag", "refs/tags/master-tag", "refs/tags/updated-tag");
}
Also used : TestRepository(org.eclipse.jgit.junit.TestRepository) Repository(org.eclipse.jgit.lib.Repository) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) RevCommit(org.eclipse.jgit.revwalk.RevCommit) RefUpdate(org.eclipse.jgit.lib.RefUpdate) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 98 with RefUpdate

use of org.eclipse.jgit.lib.RefUpdate in project gerrit by GerritCodeReview.

the class RefAdvertisementIT method uploadPackNewReachableTagVisible.

// first  ls-remote: rcBranch (c2) <- newcommit1                 <- newcommit2 (branch)
// second ls-remote: rcBranch (c2) <- newcommit1 (branch-newtag) <- newcommit2 (branch)
@Test
public void uploadPackNewReachableTagVisible() throws Exception {
    projectOperations.project(project).forUpdate().add(allow(Permission.READ).ref("refs/heads/branch").group(REGISTERED_USERS)).update();
    requestScopeOperations.setApiUser(user.id());
    try (Repository repo = repoManager.openRepository(project)) {
        // c2 <- newcommit1 (branch)
        PushOneCommit.Result r = pushFactory.create(admin.newIdent(), testRepo).setParent(rcBranch).to("refs/heads/branch");
        r.assertOkStatus();
        RevCommit tagRc = r.getCommit();
        // c2 <- newcommit1 <- newcommit2 (branch)
        r = pushFactory.create(admin.newIdent(), testRepo).setParent(tagRc).to("refs/heads/branch");
        r.assertOkStatus();
        assertUploadPackRefs(psRef2, metaRef2, psRef4, metaRef4, "refs/heads/branch", "refs/tags/branch-tag", // See comment in subsetOfBranchesVisibleNotIncludingHead.
        "refs/tags/master-tag");
        // c2 <- newcommit1 (branch-newtag) <- newcommit2 (branch)
        RefUpdate btu = repo.updateRef("refs/tags/branch-newtag");
        btu.setExpectedOldObjectId(ObjectId.zeroId());
        btu.setNewObjectId(tagRc);
        assertThat(btu.update()).isEqualTo(RefUpdate.Result.NEW);
    }
    assertUploadPackRefs(psRef2, metaRef2, psRef4, metaRef4, "refs/heads/branch", "refs/tags/branch-tag", "refs/tags/branch-newtag", // See comment in subsetOfBranchesVisibleNotIncludingHead.
    "refs/tags/master-tag");
}
Also used : TestRepository(org.eclipse.jgit.junit.TestRepository) Repository(org.eclipse.jgit.lib.Repository) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) RevCommit(org.eclipse.jgit.revwalk.RevCommit) RefUpdate(org.eclipse.jgit.lib.RefUpdate) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 99 with RefUpdate

use of org.eclipse.jgit.lib.RefUpdate in project gerrit by GerritCodeReview.

the class RefAdvertisementIT method uploadPackBranchRewindMakeTagUnreachableInVisible.

// first  ls-remote: rcBranch (c2)        <- newcommit1 (branch-oldtag) <- newcommit2 (branch)
// second ls-remote: rcBranch (c2 branch) <- newcommit1 (branch-oldtag)
@Test
public void uploadPackBranchRewindMakeTagUnreachableInVisible() throws Exception {
    projectOperations.project(project).forUpdate().add(allow(Permission.READ).ref("refs/heads/branch").group(REGISTERED_USERS)).update();
    requestScopeOperations.setApiUser(user.id());
    try (Repository repo = repoManager.openRepository(project)) {
        // rcBranch (c2) <- newcommit1 (branch)
        PushOneCommit.Result r = pushFactory.create(admin.newIdent(), testRepo).setParent(rcBranch).to("refs/heads/branch");
        r.assertOkStatus();
        RevCommit tagRc = r.getCommit();
        // rcBranch (c2) <- newcommit1 <- newcommit2 (branch)
        r = pushFactory.create(admin.newIdent(), testRepo).setParent(tagRc).to("refs/heads/branch");
        r.assertOkStatus();
        RevCommit bRc = r.getCommit();
        // rcBranch (c2) <- newcommit1 (branch-oldtag) <- newcommit2 (branch)
        RefUpdate btu = repo.updateRef("refs/tags/branch-oldtag");
        btu.setExpectedOldObjectId(ObjectId.zeroId());
        btu.setNewObjectId(tagRc);
        assertThat(btu.update()).isEqualTo(RefUpdate.Result.NEW);
        assertUploadPackRefs(psRef2, metaRef2, psRef4, metaRef4, "refs/heads/branch", "refs/tags/branch-tag", "refs/tags/branch-oldtag", // See comment in subsetOfBranchesVisibleNotIncludingHead.
        "refs/tags/master-tag");
        // rcBranch (c2 branch) <- newcommit1 (branch-oldtag) <- newcommit2
        btu = repo.updateRef("refs/heads/branch");
        btu.setExpectedOldObjectId(bRc);
        btu.setNewObjectId(rcBranch);
        btu.setForceUpdate(true);
        assertThat(btu.update()).isEqualTo(RefUpdate.Result.FORCED);
    }
    assertUploadPackRefs(psRef2, metaRef2, psRef4, metaRef4, "refs/heads/branch", "refs/tags/branch-tag", // See comment in subsetOfBranchesVisibleNotIncludingHead.
    "refs/tags/master-tag");
}
Also used : TestRepository(org.eclipse.jgit.junit.TestRepository) Repository(org.eclipse.jgit.lib.Repository) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) RevCommit(org.eclipse.jgit.revwalk.RevCommit) RefUpdate(org.eclipse.jgit.lib.RefUpdate) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 100 with RefUpdate

use of org.eclipse.jgit.lib.RefUpdate in project gerrit by GerritCodeReview.

the class RefAdvertisementIT method uploadPackBranchFFNewTagOldBranchVisible.

// first  ls-remote: rcBranch (c2) <- newcommit1 (branch)
// second ls-remote: rcBranch (c2) <- newcommit1                 <- newcommit2 (branch)
// third  ls-remote: rcBranch (c2) <- newcommit1 (branch-newtag) <- newcommit2 (branch)
@Test
public void uploadPackBranchFFNewTagOldBranchVisible() throws Exception {
    projectOperations.project(project).forUpdate().add(allow(Permission.READ).ref("refs/heads/branch").group(REGISTERED_USERS)).update();
    requestScopeOperations.setApiUser(user.id());
    try (Repository repo = repoManager.openRepository(project)) {
        // rcBranch (c2) <- newcommit1 (branch)
        PushOneCommit.Result r = pushFactory.create(admin.newIdent(), testRepo).setParent(rcBranch).to("refs/heads/branch");
        r.assertOkStatus();
        RevCommit tagRc = r.getCommit();
        assertUploadPackRefs(psRef2, metaRef2, psRef4, metaRef4, "refs/heads/branch", "refs/tags/branch-tag", // See comment in subsetOfBranchesVisibleNotIncludingHead.
        "refs/tags/master-tag");
        // rcBranch (c2) <- newcommit1 <- newcommit2 (branch)
        r = pushFactory.create(admin.newIdent(), testRepo).setParent(tagRc).to("refs/heads/branch");
        r.assertOkStatus();
        // rcBranch (c2) <- newcommit1 (branch-newtag) <- newcommit2 (branch)
        RefUpdate btu = repo.updateRef("refs/tags/branch-newtag");
        btu.setExpectedOldObjectId(ObjectId.zeroId());
        btu.setNewObjectId(tagRc);
        assertThat(btu.update()).isEqualTo(RefUpdate.Result.NEW);
    }
    assertUploadPackRefs(psRef2, metaRef2, psRef4, metaRef4, "refs/heads/branch", "refs/tags/branch-tag", "refs/tags/branch-newtag", // See comment in subsetOfBranchesVisibleNotIncludingHead.
    "refs/tags/master-tag");
}
Also used : TestRepository(org.eclipse.jgit.junit.TestRepository) Repository(org.eclipse.jgit.lib.Repository) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) RevCommit(org.eclipse.jgit.revwalk.RevCommit) RefUpdate(org.eclipse.jgit.lib.RefUpdate) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Aggregations

RefUpdate (org.eclipse.jgit.lib.RefUpdate)110 Repository (org.eclipse.jgit.lib.Repository)51 ObjectId (org.eclipse.jgit.lib.ObjectId)45 IOException (java.io.IOException)34 Test (org.junit.Test)32 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)27 TestRepository (org.eclipse.jgit.junit.TestRepository)26 ObjectInserter (org.eclipse.jgit.lib.ObjectInserter)24 RevWalk (org.eclipse.jgit.revwalk.RevWalk)23 Result (org.eclipse.jgit.lib.RefUpdate.Result)22 RevCommit (org.eclipse.jgit.revwalk.RevCommit)20 CommitBuilder (org.eclipse.jgit.lib.CommitBuilder)18 Ref (org.eclipse.jgit.lib.Ref)17 RemoteRefUpdate (org.eclipse.jgit.transport.RemoteRefUpdate)17 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)15 BatchRefUpdate (org.eclipse.jgit.lib.BatchRefUpdate)14 InMemoryRepository (org.eclipse.jgit.internal.storage.dfs.InMemoryRepository)12 LockFailureException (com.google.gerrit.git.LockFailureException)10 PersonIdent (org.eclipse.jgit.lib.PersonIdent)9 DirCache (org.eclipse.jgit.dircache.DirCache)8