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