Search in sources :

Example 41 with RefUpdate

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

the class AbstractPushForReview method pushInitialCommitForRefsMetaConfigBranch.

@Test
public void pushInitialCommitForRefsMetaConfigBranch() throws Exception {
    // delete refs/meta/config
    try (Repository repo = repoManager.openRepository(project);
        RevWalk rw = new RevWalk(repo)) {
        RefUpdate u = repo.updateRef(RefNames.REFS_CONFIG);
        u.setForceUpdate(true);
        u.setExpectedOldObjectId(repo.resolve(RefNames.REFS_CONFIG));
        assertThat(u.delete(rw)).isEqualTo(Result.FORCED);
    }
    RevCommit c = testRepo.commit().message("Initial commit").author(admin.newIdent()).committer(admin.newIdent()).insertChangeId().create();
    String id = GitUtil.getChangeId(testRepo, c).get();
    testRepo.reset(c);
    String r = "refs/for/" + RefNames.REFS_CONFIG;
    PushResult pr = pushHead(testRepo, r, false);
    assertPushOk(pr, r);
    ChangeInfo change = gApi.changes().id(id).info();
    assertThat(change.branch).isEqualTo(RefNames.REFS_CONFIG);
    assertThat(change.status).isEqualTo(ChangeStatus.NEW);
    try (Repository repo = repoManager.openRepository(project)) {
        assertThat(repo.resolve(RefNames.REFS_CONFIG)).isNull();
    }
    gApi.changes().id(change.id).current().review(ReviewInput.approve());
    gApi.changes().id(change.id).current().submit();
    try (Repository repo = repoManager.openRepository(project)) {
        assertThat(repo.resolve(RefNames.REFS_CONFIG)).isEqualTo(c);
    }
}
Also used : TestRepository(org.eclipse.jgit.junit.TestRepository) Repository(org.eclipse.jgit.lib.Repository) ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) PushResult(org.eclipse.jgit.transport.PushResult) RevWalk(org.eclipse.jgit.revwalk.RevWalk) RefUpdate(org.eclipse.jgit.lib.RefUpdate) RemoteRefUpdate(org.eclipse.jgit.transport.RemoteRefUpdate) RevCommit(org.eclipse.jgit.revwalk.RevCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 42 with RefUpdate

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

the class RefAdvertisementIT method uploadPackNewCommitOrphanTagInvisible.

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

Example 43 with RefUpdate

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

the class AutoMergeIT method deleteAutoMergeBranch.

private void deleteAutoMergeBranch(ObjectId mergeCommit) throws Exception {
    try (Repository repo = repoManager.openRepository(project)) {
        RefUpdate ru = repo.updateRef(RefNames.refsCacheAutomerge(mergeCommit.name()));
        ru.setForceUpdate(true);
        assertThat(ru.delete()).isEqualTo(RefUpdate.Result.FORCED);
    }
    assertNoAutoMergeCreated(mergeCommit);
}
Also used : Repository(org.eclipse.jgit.lib.Repository) RefUpdate(org.eclipse.jgit.lib.RefUpdate)

Example 44 with RefUpdate

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

the class RefAdvertisementIT method uploadPackTagUpdatedUnreachableInvisible.

// first  ls-remote: rcBranch (c2 branch updated-tag)
// second ls-remote: rcBranch (c2 branch)             <- newcommit1 (updated-tag)
@Test
public void uploadPackTagUpdatedUnreachableInvisible() 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 updated-tag)
        RefUpdate btu = repo.updateRef("refs/tags/updated-tag");
        btu.setExpectedOldObjectId(ObjectId.zeroId());
        btu.setNewObjectId(rcBranch);
        assertThat(btu.update()).isEqualTo(RefUpdate.Result.NEW);
        assertUploadPackRefs(psRef2, metaRef2, psRef4, metaRef4, "refs/heads/branch", "refs/tags/branch-tag", "refs/tags/master-tag", "refs/tags/updated-tag");
        // rcBranch (c2 branch) <- newcommit1 (updated-tag)
        PushOneCommit.Result r = pushFactory.create(admin.newIdent(), testRepo).setParent(rcBranch).to("refs/tags/updated-tag");
        r.assertOkStatus();
    }
    assertUploadPackRefs(psRef2, metaRef2, psRef4, metaRef4, "refs/heads/branch", "refs/tags/branch-tag", "refs/tags/master-tag");
}
Also used : TestRepository(org.eclipse.jgit.junit.TestRepository) Repository(org.eclipse.jgit.lib.Repository) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) RefUpdate(org.eclipse.jgit.lib.RefUpdate) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 45 with RefUpdate

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

the class RefAdvertisementIT method uploadPackTagDeleted.

// first  ls-remote: rcBranch (c2 branch branch-tag)
// second ls-remote: rcBranch (c2 branch)
@Test
public void uploadPackTagDeleted() throws Exception {
    projectOperations.project(project).forUpdate().add(allow(Permission.READ).ref("refs/heads/branch").group(REGISTERED_USERS)).add(allow(Permission.DELETE).ref("refs/tags/branch-tag").group(REGISTERED_USERS)).add(allow(Permission.PUSH).ref("refs/tags/branch-tag").group(REGISTERED_USERS)).update();
    requestScopeOperations.setApiUser(user.id());
    // rcBranch (c2 branch branch-tag)
    assertUploadPackRefs(psRef2, metaRef2, psRef4, metaRef4, "refs/heads/branch", "refs/tags/branch-tag", "refs/tags/master-tag");
    // rcBranch (c2 branch)
    try (Repository repo = repoManager.openRepository(project)) {
        RefUpdate btu = repo.updateRef("refs/tags/branch-tag");
        btu.setExpectedOldObjectId(rcBranch);
        btu.setNewObjectId(ObjectId.zeroId());
        btu.setForceUpdate(true);
        assertThat(btu.delete()).isEqualTo(RefUpdate.Result.FORCED);
    }
    assertUploadPackRefs(psRef2, metaRef2, psRef4, metaRef4, "refs/heads/branch", "refs/tags/master-tag");
}
Also used : TestRepository(org.eclipse.jgit.junit.TestRepository) Repository(org.eclipse.jgit.lib.Repository) 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