Search in sources :

Example 31 with Repository

use of org.eclipse.jgit.lib.Repository in project gitblit by gitblit.

the class LuceneExecutorTest method testMultiSearch.

@Test
public void testMultiSearch() throws Exception {
    List<String> list = new ArrayList<String>();
    Repository repository = GitBlitSuite.getHelloworldRepository();
    list.add(newRepositoryModel(repository).name);
    repository.close();
    repository = GitBlitSuite.getJGitRepository();
    list.add(newRepositoryModel(repository).name);
    repository.close();
    List<SearchResult> results = lucene.search("test", 1, 10, list);
    assertEquals(10, results.size());
}
Also used : Repository(org.eclipse.jgit.lib.Repository) ArrayList(java.util.ArrayList) SearchResult(com.gitblit.models.SearchResult) Test(org.junit.Test)

Example 32 with Repository

use of org.eclipse.jgit.lib.Repository in project gitblit by gitblit.

the class LuceneExecutorTest method testIndex.

@Test
public void testIndex() {
    // reindex helloworld
    Repository repository = GitBlitSuite.getHelloworldRepository();
    RepositoryModel model = newRepositoryModel(repository);
    lucene.reindex(model, repository);
    repository.close();
    SearchResult result = lucene.search("type:blob AND path:bit.bit", 1, 1, model.name).get(0);
    assertEquals("Mike Donaghy", result.author);
    result = lucene.search("type:blob AND path:clipper.prg", 1, 1, model.name).get(0);
    assertEquals("tinogomes", result.author);
    // reindex JGit
    repository = GitBlitSuite.getJGitRepository();
    model = newRepositoryModel(repository);
    lucene.reindex(model, repository);
    repository.close();
}
Also used : Repository(org.eclipse.jgit.lib.Repository) SearchResult(com.gitblit.models.SearchResult) RepositoryModel(com.gitblit.models.RepositoryModel) Test(org.junit.Test)

Example 33 with Repository

use of org.eclipse.jgit.lib.Repository in project gitblit by gitblit.

the class JGitUtilsTest method testCommitNotes.

@Test
public void testCommitNotes() throws Exception {
    Repository repository = GitBlitSuite.getJGitRepository();
    RevCommit commit = JGitUtils.getCommit(repository, "690c268c793bfc218982130fbfc25870f292295e");
    List<GitNote> list = JGitUtils.getNotesOnCommit(repository, commit);
    repository.close();
    assertTrue(list.size() > 0);
    assertEquals("183474d554e6f68478a02d9d7888b67a9338cdff", list.get(0).notesRef.getReferencedObjectId().getName());
}
Also used : Repository(org.eclipse.jgit.lib.Repository) GitNote(com.gitblit.models.GitNote) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Test(org.junit.Test)

Example 34 with Repository

use of org.eclipse.jgit.lib.Repository in project gitblit by gitblit.

the class JGitUtilsTest method testCreateRepositoryShared.

@Test
public void testCreateRepositoryShared() throws Exception {
    String[] repositories = { "NewSharedTestRepository.git" };
    for (String repositoryName : repositories) {
        Repository repository = JGitUtils.createRepository(GitBlitSuite.REPOSITORIES, repositoryName, "group");
        File folder = FileKey.resolve(new File(GitBlitSuite.REPOSITORIES, repositoryName), FS.DETECTED);
        assertNotNull(repository);
        assertFalse(JGitUtils.hasCommits(repository));
        assertNull(JGitUtils.getFirstCommit(repository, null));
        assertEquals("1", repository.getConfig().getString("core", null, "sharedRepository"));
        assertTrue(folder.exists());
        if (!JnaUtils.isWindows()) {
            int mode = JnaUtils.getFilemode(folder);
            assertEquals(JnaUtils.S_ISGID, mode & JnaUtils.S_ISGID);
            assertEquals(JnaUtils.S_IRWXG, mode & JnaUtils.S_IRWXG);
            mode = JnaUtils.getFilemode(folder.getAbsolutePath() + "/HEAD");
            assertEquals(JnaUtils.S_IRGRP | JnaUtils.S_IWGRP, mode & JnaUtils.S_IRWXG);
            mode = JnaUtils.getFilemode(folder.getAbsolutePath() + "/config");
            assertEquals(JnaUtils.S_IRGRP | JnaUtils.S_IWGRP, mode & JnaUtils.S_IRWXG);
        }
        repository.close();
        RepositoryCache.close(repository);
        FileUtils.delete(repository.getDirectory(), FileUtils.RECURSIVE);
    }
}
Also used : Repository(org.eclipse.jgit.lib.Repository) File(java.io.File) Test(org.junit.Test)

Example 35 with Repository

use of org.eclipse.jgit.lib.Repository in project gitblit by gitblit.

the class JGitUtilsTest method testBranches.

@Test
public void testBranches() throws Exception {
    Repository repository = GitBlitSuite.getJGitRepository();
    assertTrue(JGitUtils.getLocalBranches(repository, true, 0).size() == 0);
    for (RefModel model : JGitUtils.getLocalBranches(repository, true, -1)) {
        assertTrue(model.getName().startsWith(Constants.R_HEADS));
        assertTrue(model.equals(model));
        assertFalse(model.equals(""));
        assertTrue(model.hashCode() == model.getReferencedObjectId().hashCode() + model.getName().hashCode());
        assertTrue(model.getShortMessage().equals(model.getShortMessage()));
    }
    for (RefModel model : JGitUtils.getRemoteBranches(repository, true, -1)) {
        assertTrue(model.getName().startsWith(Constants.R_REMOTES));
        assertTrue(model.equals(model));
        assertFalse(model.equals(""));
        assertTrue(model.hashCode() == model.getReferencedObjectId().hashCode() + model.getName().hashCode());
        assertTrue(model.getShortMessage().equals(model.getShortMessage()));
    }
    assertTrue(JGitUtils.getRemoteBranches(repository, true, 8).size() == 8);
    repository.close();
}
Also used : Repository(org.eclipse.jgit.lib.Repository) RefModel(com.gitblit.models.RefModel) Test(org.junit.Test)

Aggregations

Repository (org.eclipse.jgit.lib.Repository)326 IOException (java.io.IOException)103 RevWalk (org.eclipse.jgit.revwalk.RevWalk)102 Test (org.junit.Test)81 RevCommit (org.eclipse.jgit.revwalk.RevCommit)76 ObjectId (org.eclipse.jgit.lib.ObjectId)72 File (java.io.File)43 TestRepository (org.eclipse.jgit.junit.TestRepository)40 Change (com.google.gerrit.reviewdb.client.Change)39 OrmException (com.google.gwtorm.server.OrmException)39 Ref (org.eclipse.jgit.lib.Ref)35 Project (com.google.gerrit.reviewdb.client.Project)32 ArrayList (java.util.ArrayList)31 ObjectInserter (org.eclipse.jgit.lib.ObjectInserter)27 InMemoryRepository (org.eclipse.jgit.internal.storage.dfs.InMemoryRepository)26 PatchSet (com.google.gerrit.reviewdb.client.PatchSet)24 Map (java.util.Map)23 ConfigInvalidException (org.eclipse.jgit.errors.ConfigInvalidException)23 RepositoryModel (com.gitblit.models.RepositoryModel)20 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)20