Search in sources :

Example 31 with FileRepository

use of org.eclipse.jgit.internal.storage.file.FileRepository in project gerrit by GerritCodeReview.

the class AllProjectsConfigTest method baseConfig.

@Test
public void baseConfig() throws Exception {
    assertThat(getConfig().getString("foo", null, "bar")).isNull();
    Path baseConfigPath = sitePaths.etc_dir.resolve(ALL_PROJECTS).resolve("project.config");
    Files.createDirectories(baseConfigPath.getParent());
    Files.write(baseConfigPath, ImmutableList.of("[foo]", "bar = base"));
    assertThat(getConfig().getString("foo", null, "bar")).isEqualTo("base");
    try (Repository repo = new FileRepository(allProjectsRepoFile);
        TestRepository<Repository> tr = new TestRepository<>(repo)) {
        tr.branch("refs/meta/config").commit().add("project.config", "[foo]\nbar = baz").create();
    }
    assertThat(getConfig().getString("foo", null, "bar")).isEqualTo("baz");
}
Also used : Path(java.nio.file.Path) FileRepository(org.eclipse.jgit.internal.storage.file.FileRepository) TestRepository(org.eclipse.jgit.junit.TestRepository) FileRepository(org.eclipse.jgit.internal.storage.file.FileRepository) Repository(org.eclipse.jgit.lib.Repository) TestRepository(org.eclipse.jgit.junit.TestRepository) Test(org.junit.Test)

Example 32 with FileRepository

use of org.eclipse.jgit.internal.storage.file.FileRepository in project gerrit by GerritCodeReview.

the class AllProjectsConfigTest method setUp.

@Before
public void setUp() throws Exception {
    sitePaths = new SitePaths(temporaryFolder.newFolder().toPath());
    Files.createDirectories(sitePaths.etc_dir);
    Path gitPath = sitePaths.resolve("git");
    StoredConfig gerritConfig = new FileBasedConfig(sitePaths.resolve("etc").resolve("gerrit.config").toFile(), FS.DETECTED);
    gerritConfig.load();
    gerritConfig.setString("gerrit", null, "basePath", gitPath.toAbsolutePath().toString());
    gerritConfig.setString("gerrit", null, "allProjects", ALL_PROJECTS);
    gerritConfig.save();
    Files.createDirectories(sitePaths.resolve("git"));
    allProjectsRepoFile = gitPath.resolve("All-The-Projects.git").toFile();
    try (Repository repo = new FileRepository(allProjectsRepoFile)) {
        repo.create(true);
    }
    InMemorySecureStore secureStore = new InMemorySecureStore();
    InitFlags flags = new InitFlags(sitePaths, secureStore, ImmutableList.of(), false);
    Section.Factory sections = (name, subsection) -> new Section(flags, sitePaths, secureStore, ui, name, subsection);
    AllProjectsConfigProvider configProvider = new FileBasedAllProjectsConfigProvider(sitePaths);
    allProjectsConfig = new AllProjectsConfig(new AllProjectsNameOnInitProvider(sections), configProvider, sitePaths, flags);
}
Also used : Path(java.nio.file.Path) ConfigInvalidException(org.eclipse.jgit.errors.ConfigInvalidException) Mock(org.mockito.Mock) RunWith(org.junit.runner.RunWith) InMemorySecureStore(com.google.gerrit.server.securestore.testing.InMemorySecureStore) FileBasedAllProjectsConfigProvider(com.google.gerrit.server.config.FileBasedAllProjectsConfigProvider) Config(org.eclipse.jgit.lib.Config) ImmutableList(com.google.common.collect.ImmutableList) Path(java.nio.file.Path) Before(org.junit.Before) TestRepository(org.eclipse.jgit.junit.TestRepository) Files(java.nio.file.Files) FileRepository(org.eclipse.jgit.internal.storage.file.FileRepository) IOException(java.io.IOException) Test(org.junit.Test) Truth.assertThat(com.google.common.truth.Truth.assertThat) File(java.io.File) FileBasedConfig(org.eclipse.jgit.storage.file.FileBasedConfig) Rule(org.junit.Rule) SitePaths(com.google.gerrit.server.config.SitePaths) StoredConfig(org.eclipse.jgit.lib.StoredConfig) FS(org.eclipse.jgit.util.FS) AllProjectsConfigProvider(com.google.gerrit.server.config.AllProjectsConfigProvider) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) Repository(org.eclipse.jgit.lib.Repository) TemporaryFolder(org.junit.rules.TemporaryFolder) FileRepository(org.eclipse.jgit.internal.storage.file.FileRepository) SitePaths(com.google.gerrit.server.config.SitePaths) StoredConfig(org.eclipse.jgit.lib.StoredConfig) TestRepository(org.eclipse.jgit.junit.TestRepository) FileRepository(org.eclipse.jgit.internal.storage.file.FileRepository) Repository(org.eclipse.jgit.lib.Repository) FileBasedAllProjectsConfigProvider(com.google.gerrit.server.config.FileBasedAllProjectsConfigProvider) InMemorySecureStore(com.google.gerrit.server.securestore.testing.InMemorySecureStore) FileBasedAllProjectsConfigProvider(com.google.gerrit.server.config.FileBasedAllProjectsConfigProvider) AllProjectsConfigProvider(com.google.gerrit.server.config.AllProjectsConfigProvider) FileBasedConfig(org.eclipse.jgit.storage.file.FileBasedConfig) Before(org.junit.Before)

Example 33 with FileRepository

use of org.eclipse.jgit.internal.storage.file.FileRepository in project gerrit by GerritCodeReview.

the class ProjectConfigSchemaUpdateTest method noBaseConfig.

@Test
public void noBaseConfig() throws Exception {
    assertThat(getConfig().getString("foo", null, "bar")).isNull();
    try (Repository repo = new FileRepository(allProjectsRepoFile);
        TestRepository<Repository> tr = new TestRepository<>(repo)) {
        tr.branch("refs/meta/config").commit().add("project.config", "[foo]\nbar = baz").create();
    }
    assertThat(getConfig().getString("foo", null, "bar")).isEqualTo("baz");
}
Also used : FileRepository(org.eclipse.jgit.internal.storage.file.FileRepository) TestRepository(org.eclipse.jgit.junit.TestRepository) FileRepository(org.eclipse.jgit.internal.storage.file.FileRepository) Repository(org.eclipse.jgit.lib.Repository) TestRepository(org.eclipse.jgit.junit.TestRepository) Test(org.junit.Test)

Example 34 with FileRepository

use of org.eclipse.jgit.internal.storage.file.FileRepository in project gerrit by GerritCodeReview.

the class ProjectConfigSchemaUpdateTest method setUp.

@Before
public void setUp() throws Exception {
    sitePaths = new SitePaths(temporaryFolder.newFolder().toPath());
    Files.createDirectories(sitePaths.etc_dir);
    Path gitPath = sitePaths.resolve("git");
    StoredConfig gerritConfig = new FileBasedConfig(sitePaths.gerrit_config.toFile(), FS.DETECTED);
    gerritConfig.load();
    gerritConfig.setString("gerrit", null, "basePath", gitPath.toAbsolutePath().toString());
    gerritConfig.setString("gerrit", null, "allProjects", ALL_PROJECTS);
    gerritConfig.save();
    Files.createDirectories(sitePaths.resolve("git"));
    allProjectsRepoFile = gitPath.resolve("All-The-Projects.git").toFile();
    try (Repository repo = new FileRepository(allProjectsRepoFile)) {
        repo.create(true);
    }
    FileBasedAllProjectsConfigProvider configProvider = new FileBasedAllProjectsConfigProvider(sitePaths);
    factory = new ProjectConfigSchemaUpdate.Factory(new AllProjectsName(ALL_PROJECTS), configProvider);
}
Also used : Path(java.nio.file.Path) StoredConfig(org.eclipse.jgit.lib.StoredConfig) FileRepository(org.eclipse.jgit.internal.storage.file.FileRepository) TestRepository(org.eclipse.jgit.junit.TestRepository) FileRepository(org.eclipse.jgit.internal.storage.file.FileRepository) Repository(org.eclipse.jgit.lib.Repository) FileBasedAllProjectsConfigProvider(com.google.gerrit.server.config.FileBasedAllProjectsConfigProvider) AllProjectsName(com.google.gerrit.server.config.AllProjectsName) SitePaths(com.google.gerrit.server.config.SitePaths) FileBasedConfig(org.eclipse.jgit.storage.file.FileBasedConfig) Before(org.junit.Before)

Aggregations

FileRepository (org.eclipse.jgit.internal.storage.file.FileRepository)34 Repository (org.eclipse.jgit.lib.Repository)29 Git (org.eclipse.jgit.api.Git)18 File (java.io.File)16 TestRepository (org.eclipse.jgit.junit.TestRepository)6 IOException (java.io.IOException)5 Test (org.junit.Test)5 Path (java.nio.file.Path)4 ArrayList (java.util.ArrayList)4 Before (org.junit.Before)4 GerritPersonIdentProvider (com.google.gerrit.server.GerritPersonIdentProvider)3 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)3 ObjectId (org.eclipse.jgit.lib.ObjectId)3 ObjectInserter (org.eclipse.jgit.lib.ObjectInserter)3 PersonIdent (org.eclipse.jgit.lib.PersonIdent)3 RevCommit (org.eclipse.jgit.revwalk.RevCommit)3 FileBasedAllProjectsConfigProvider (com.google.gerrit.server.config.FileBasedAllProjectsConfigProvider)2 SitePaths (com.google.gerrit.server.config.SitePaths)2 RepositoryChanged (com.searchcode.app.dto.RepositoryChanged)2 ObjectReader (org.eclipse.jgit.lib.ObjectReader)2