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);
}
}
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");
}
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);
}
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");
}
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");
}
Aggregations