use of org.eclipse.jgit.lib.RefUpdate in project gerrit by GerritCodeReview.
the class GroupsIT method createBranch.
private void createBranch(Project.NameKey project, String ref) throws IOException {
try (Repository r = repoManager.openRepository(project);
ObjectInserter oi = r.newObjectInserter();
RevWalk rw = new RevWalk(r)) {
ObjectId emptyCommit = createCommit(r, "Test change");
RefUpdate updateRef = r.updateRef(ref);
updateRef.setExpectedOldObjectId(ObjectId.zeroId());
updateRef.setNewObjectId(emptyCommit);
assertThat(updateRef.update(rw)).isEqualTo(RefUpdate.Result.NEW);
}
}
use of org.eclipse.jgit.lib.RefUpdate in project gerrit by GerritCodeReview.
the class CheckAccessIT method noBranches.
@Test
public void noBranches() throws Exception {
try (Repository repo = repoManager.openRepository(normalProject)) {
RefUpdate u = repo.updateRef(RefNames.REFS_HEADS + "master");
u.setForceUpdate(true);
assertThat(u.delete()).isEqualTo(Result.FORCED);
}
AccessCheckInput input = new AccessCheckInput();
input.account = privilegedUser.email();
AccessCheckInfo info = gApi.projects().name(normalProject.get()).checkAccess(input);
assertThat(info.status).isEqualTo(200);
assertThat(info.message).contains("no branches");
}
use of org.eclipse.jgit.lib.RefUpdate in project gerrit by GerritCodeReview.
the class GroupsIT method stalenessChecker.
@Test
@IgnoreGroupInconsistencies
public void stalenessChecker() throws Exception {
// Newly created group is not stale
GroupInfo groupInfo = gApi.groups().create(name("foo")).get();
AccountGroup.UUID groupUuid = AccountGroup.uuid(groupInfo.id);
assertThat(stalenessChecker.check(groupUuid).isStale()).isFalse();
// Manual update makes index document stale
String groupRef = RefNames.refsGroups(groupUuid);
try (Repository repo = repoManager.openRepository(allUsers);
RevWalk rw = new RevWalk(repo)) {
RevCommit commit = rw.parseCommit(repo.exactRef(groupRef).getObjectId());
ObjectId emptyCommit = createCommit(repo, commit.getFullMessage(), commit.getTree());
RefUpdate updateRef = repo.updateRef(groupRef);
updateRef.setExpectedOldObjectId(commit.toObjectId());
updateRef.setNewObjectId(emptyCommit);
assertThat(updateRef.forceUpdate()).isEqualTo(RefUpdate.Result.FORCED);
}
assertStaleGroupAndReindex(groupUuid);
// Manually delete group
try (Repository repo = repoManager.openRepository(allUsers);
RevWalk rw = new RevWalk(repo)) {
RevCommit commit = rw.parseCommit(repo.exactRef(groupRef).getObjectId());
RefUpdate updateRef = repo.updateRef(groupRef);
updateRef.setExpectedOldObjectId(commit.toObjectId());
updateRef.setNewObjectId(ObjectId.zeroId());
updateRef.setForceUpdate(true);
assertThat(updateRef.delete()).isEqualTo(RefUpdate.Result.FORCED);
}
assertStaleGroupAndReindex(groupUuid);
}
use of org.eclipse.jgit.lib.RefUpdate in project gerrit by GerritCodeReview.
the class GroupsIT method deleteGroupRef.
private void deleteGroupRef(String groupId) throws Exception {
AccountGroup.UUID uuid = AccountGroup.uuid(groupId);
try (Repository repo = repoManager.openRepository(allUsers)) {
RefUpdate ru = repo.updateRef(RefNames.refsGroups(uuid));
ru.setForceUpdate(true);
ru.setNewObjectId(ObjectId.zeroId());
assertThat(ru.delete()).isEqualTo(RefUpdate.Result.FORCED);
}
// Reindex the group.
gApi.groups().id(uuid.get()).index();
// Verify "sub-group" has been deleted.
assertThrows(ResourceNotFoundException.class, () -> gApi.groups().id(uuid.get()).get());
}
use of org.eclipse.jgit.lib.RefUpdate in project gerrit by GerritCodeReview.
the class RefOperationValidationIT method rejectRefUpdateNonFastForwardToExistingCommit.
@Test
public void rejectRefUpdateNonFastForwardToExistingCommit() throws Exception {
gApi.projects().name(project.get()).branch(TEST_REF).create(new BranchInput());
try (Registration registration = testValidator(UPDATE_NONFASTFORWARD)) {
grant(Permission.PUSH);
PushOneCommit push1 = pushFactory.create(admin.newIdent(), testRepo, "change1", "a.txt", "content");
PushOneCommit.Result r1 = push1.to("refs/heads/master");
r1.assertOkStatus();
ObjectId push1Id = r1.getCommit();
PushOneCommit push2 = pushFactory.create(admin.newIdent(), testRepo, "change2", "b.txt", "content");
PushOneCommit.Result r2 = push2.to("refs/heads/master");
r2.assertOkStatus();
ObjectId push2Id = r2.getCommit();
RefUpdate ru = repo().updateRef(HEAD);
ru.setNewObjectId(push1Id);
assertThat(ru.forceUpdate()).isEqualTo(RefUpdate.Result.FORCED);
PushOneCommit push3 = pushFactory.create(admin.newIdent(), testRepo, "change3", "c.txt", "content");
PushOneCommit.Result r3 = push3.to(TEST_REF);
r3.assertOkStatus();
ru = repo().updateRef(HEAD);
ru.setNewObjectId(push2Id);
assertThat(ru.forceUpdate()).isEqualTo(RefUpdate.Result.FORCED);
PushOneCommit push4 = pushFactory.create(admin.newIdent(), testRepo, "change4", "d.txt", "content");
push4.setForce(true);
PushOneCommit.Result r4 = push4.to(TEST_REF);
r4.assertErrorStatus(UPDATE_NONFASTFORWARD.name());
}
}
Aggregations