use of com.google.gerrit.entities.Project in project gerrit by GerritCodeReview.
the class ProjectLevelConfigIT method withMergedInheritance.
@Test
public void withMergedInheritance() throws Exception {
String configName = "test.config";
Config parentCfg = new Config();
parentCfg.setString("s1", null, "k1", "parentValue1");
parentCfg.setString("s1", null, "k2", "parentValue2");
parentCfg.setString("s2", "ss", "k3", "parentValue3");
parentCfg.setString("s2", "ss", "k4", "parentValue4");
pushFactory.create(admin.newIdent(), testRepo, "Create Project Level Config", configName, parentCfg.toText()).to(RefNames.REFS_CONFIG).assertOkStatus();
Project.NameKey childProject = projectOperations.newProject().parent(project).create();
TestRepository<?> childTestRepo = cloneProject(childProject);
fetch(childTestRepo, RefNames.REFS_CONFIG + ":refs/heads/config");
childTestRepo.reset("refs/heads/config");
Config cfg = new Config();
cfg.setString("s1", null, "k1", "parentValue1");
cfg.setString("s1", null, "k2", "parentValue2");
cfg.setString("s2", "ss", "k3", "parentValue3");
cfg.setString("s2", "ss", "k4", "parentValue4");
cfg.setString("s1", null, "k1", "childValue1");
cfg.setString("s2", "ss", "k3", "childValue2");
cfg.setString("s3", null, "k5", "childValue3");
cfg.setString("s3", "ss", "k6", "childValue4");
pushFactory.create(admin.newIdent(), childTestRepo, "Create Project Level Config", configName, cfg.toText()).to(RefNames.REFS_CONFIG).assertOkStatus();
ProjectState state = projectCache.get(childProject).get();
Config expectedCfg = new Config();
expectedCfg.setStringList("s1", null, "k1", Arrays.asList("childValue1", "parentValue1"));
expectedCfg.setString("s1", null, "k2", "parentValue2");
expectedCfg.setStringList("s2", "ss", "k3", Arrays.asList("childValue2", "parentValue3"));
expectedCfg.setString("s2", "ss", "k4", "parentValue4");
expectedCfg.setString("s3", null, "k5", "childValue3");
expectedCfg.setString("s3", "ss", "k6", "childValue4");
assertThat(state.getConfig(configName).getWithInheritance(/* merge= */
true).toText()).isEqualTo(expectedCfg.toText());
assertThat(state.getConfig(configName).get().toText()).isEqualTo(cfg.toText());
}
use of com.google.gerrit.entities.Project in project gerrit by GerritCodeReview.
the class DiffOperationsImpl method loadModifiedFilesWithoutCache.
/**
* Loads the modified file paths between two commits without inspecting the diff cache.
*/
private static Map<String, ModifiedFile> loadModifiedFilesWithoutCache(Project.NameKey project, DiffParameters diffParams, RevWalk revWalk, Config repoConfig) throws DiffNotAvailableException {
ObjectId newCommit = diffParams.newCommit();
ObjectId oldCommit = diffParams.baseCommit();
try {
ObjectReader reader = revWalk.getObjectReader();
List<DiffEntry> diffEntries;
try (DiffFormatter df = new DiffFormatter(DisabledOutputStream.INSTANCE)) {
df.setReader(reader, repoConfig);
df.setDetectRenames(false);
diffEntries = df.scan(oldCommit.equals(ObjectId.zeroId()) ? null : oldCommit, newCommit);
}
List<ModifiedFile> modifiedFiles = diffEntries.stream().map(entry -> ModifiedFile.builder().changeType(toChangeType(entry.getChangeType())).oldPath(getGitPath(entry.getOldPath())).newPath(getGitPath(entry.getNewPath())).build()).collect(Collectors.toList());
return DiffUtil.mergeRewrittenModifiedFiles(modifiedFiles).stream().collect(ImmutableMap.toImmutableMap(ModifiedFile::getDefaultPath, Function.identity()));
} catch (IOException e) {
throw new DiffNotAvailableException(String.format("Failed to compute the modified files for project '%s'," + " old commit '%s', new commit '%s'.", project, oldCommit.name(), newCommit.name()), e);
}
}
use of com.google.gerrit.entities.Project in project gerrit by GerritCodeReview.
the class BranchesCollection method parse.
@Override
public BranchResource parse(ProjectResource parent, IdString id) throws RestApiException, IOException, PermissionBackendException {
parent.getProjectState().checkStatePermitsRead();
Project.NameKey project = parent.getNameKey();
try (Repository repo = repoManager.openRepository(project)) {
Ref ref = repo.exactRef(RefNames.fullName(id.get()));
if (ref == null) {
throw new ResourceNotFoundException(id);
}
// ListBranches checks the target of a symbolic reference to determine access
// rights on the symbolic reference itself. This check prevents seeing a hidden
// branch simply because the symbolic reference name was visible.
permissionBackend.currentUser().project(project).ref(ref.isSymbolic() ? ref.getTarget().getName() : ref.getName()).check(RefPermission.READ);
return new BranchResource(parent.getProjectState(), parent.getUser(), ref);
} catch (AuthException notAllowed) {
throw new ResourceNotFoundException(id, notAllowed);
} catch (RepositoryNotFoundException noRepo) {
throw new ResourceNotFoundException(id, noRepo);
}
}
use of com.google.gerrit.entities.Project in project gerrit by GerritCodeReview.
the class WalkSorterTest method newChange.
private ChangeData newChange(TestRepository<Repo> tr, ObjectId id) throws Exception {
Project.NameKey project = tr.getRepository().getDescription().getProject();
Change c = TestChanges.newChange(project, userId);
ChangeData cd = ChangeData.createForTest(project, c.getId(), 1, id);
cd.setChange(c);
cd.setPatchSets(ImmutableList.of(cd.currentPatchSet()));
return cd;
}
use of com.google.gerrit.entities.Project in project gerrit by GerritCodeReview.
the class ProjectSerializerTest method roundTripWithMinimalValues.
@Test
public void roundTripWithMinimalValues() {
Project projectAutoValue = Project.builder(Project.nameKey("test")).setSubmitType(SubmitType.FAST_FORWARD_ONLY).setState(ProjectState.HIDDEN).build();
assertThat(deserialize(serialize(projectAutoValue))).isEqualTo(projectAutoValue);
}
Aggregations