use of com.google.gerrit.entities.Project in project gerrit by GerritCodeReview.
the class PermissionBackendConditionIT method projectPermissions_differentResourceSameUserDoesNotEqual.
@Test
public void projectPermissions_differentResourceSameUserDoesNotEqual() throws Exception {
Project.NameKey project2 = projectOperations.newProject().create();
BooleanCondition cond1 = pb.user(user()).project(project).testCond(ProjectPermission.READ);
BooleanCondition cond2 = pb.user(user()).project(project2).testCond(ProjectPermission.READ);
assertNotEquals(cond1, cond2);
assertNotEquals(cond1.hashCode(), cond2.hashCode());
}
use of com.google.gerrit.entities.Project in project gerrit by GerritCodeReview.
the class CherryPickCommit method apply.
@Override
public Response<ChangeInfo> apply(CommitResource rsrc, CherryPickInput input) throws IOException, UpdateException, RestApiException, PermissionBackendException, ConfigInvalidException, NoSuchProjectException {
String destination = Strings.nullToEmpty(input.destination).trim();
input.parent = input.parent == null ? 1 : input.parent;
Project.NameKey projectName = rsrc.getProjectState().getNameKey();
if (destination.isEmpty()) {
throw new BadRequestException("destination must be non-empty");
}
String refName = RefNames.fullName(destination);
contributorAgreements.check(projectName, user.get());
permissionBackend.currentUser().project(projectName).ref(refName).check(RefPermission.CREATE_CHANGE);
rsrc.getProjectState().checkStatePermitsWrite();
try {
CherryPickChange.Result cherryPickResult = cherryPickChange.cherryPick(null, projectName, rsrc.getCommit(), input, BranchNameKey.create(rsrc.getProjectState().getNameKey(), refName));
ChangeInfo changeInfo = json.noOptions().format(projectName, cherryPickResult.changeId());
changeInfo.containsGitConflicts = !cherryPickResult.filesWithGitConflicts().isEmpty() ? true : null;
return Response.ok(changeInfo);
} catch (InvalidChangeOperationException e) {
throw new BadRequestException(e.getMessage());
}
}
use of com.google.gerrit.entities.Project in project gerrit by GerritCodeReview.
the class ProjectResetterTest method projectEvictionIfRefsMetaConfigIsReset.
@Test
public void projectEvictionIfRefsMetaConfigIsReset() throws Exception {
Project.NameKey project2 = Project.nameKey("bar");
Repository repo2 = repoManager.createRepository(project2);
Ref metaConfig = createRef(repo2, RefNames.REFS_CONFIG);
ProjectCache projectCache = mock(ProjectCache.class);
Ref nonMetaConfig = createRef("refs/heads/master");
try (ProjectResetter resetProject = builder(null, null, null, null, null, null, projectCache).build(new ProjectResetter.Config().reset(project).reset(project2))) {
updateRef(nonMetaConfig);
updateRef(repo2, metaConfig);
}
verify(projectCache, only()).evictAndReindex(project2);
}
use of com.google.gerrit.entities.Project in project gerrit by GerritCodeReview.
the class ProjectResetterTest method onlyDeleteNewlyCreatedMatchingRefsMultipleProjects.
@Test
public void onlyDeleteNewlyCreatedMatchingRefsMultipleProjects() throws Exception {
Project.NameKey project2 = Project.nameKey("bar");
Repository repo2 = repoManager.createRepository(project2);
Ref matchingRefProject1;
Ref nonMatchingRefProject1;
Ref matchingRefProject2;
Ref nonMatchingRefProject2;
try (ProjectResetter resetProject = builder().build(new ProjectResetter.Config().reset(project, "refs/foo/*").reset(project2, "refs/bar/*"))) {
matchingRefProject1 = createRef("refs/foo/test");
nonMatchingRefProject1 = createRef("refs/bar/test");
matchingRefProject2 = createRef(repo2, "refs/bar/test");
nonMatchingRefProject2 = createRef(repo2, "refs/foo/test");
}
// The matching refs are deleted since they didn't exist before.
assertDeletedRef(matchingRefProject1);
assertDeletedRef(repo2, matchingRefProject2);
// The non-matching ref is not deleted.
assertRef(nonMatchingRefProject1);
assertRef(repo2, nonMatchingRefProject2);
}
use of com.google.gerrit.entities.Project in project gerrit by GerritCodeReview.
the class ConfigChangeIT method rejectDoubleInheritance.
@Test
public void rejectDoubleInheritance() throws Exception {
requestScopeOperations.setApiUser(admin.id());
// Create separate projects to test the config
Project.NameKey parent = createProjectOverAPI("projectToInheritFrom", null, true, null);
Project.NameKey child = createProjectOverAPI("projectWithMalformedConfig", null, true, null);
String config = gApi.projects().name(child.get()).branch(RefNames.REFS_CONFIG).file("project.config").asString();
// Append and push malformed project config
String pattern = "[access]\n\tinheritFrom = " + allProjects.get() + "\n";
String doubleInherit = pattern + "\tinheritFrom = " + parent.get() + "\n";
config = config.replace(pattern, doubleInherit);
TestRepository<InMemoryRepository> childRepo = cloneProject(child, admin);
// Fetch meta ref
GitUtil.fetch(childRepo, RefNames.REFS_CONFIG + ":cfg");
childRepo.reset("cfg");
PushOneCommit push = pushFactory.create(admin.newIdent(), childRepo, "Subject", "project.config", config);
PushOneCommit.Result res = push.to(RefNames.REFS_CONFIG);
res.assertErrorStatus();
res.assertMessage("cannot inherit from multiple projects");
}
Aggregations