Search in sources :

Example 36 with Repository

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

the class JGitUtilsTest method testCreateRepositorySharedCustom.

@Test
public void testCreateRepositorySharedCustom() throws Exception {
    String[] repositories = { "NewSharedTestRepository.git" };
    for (String repositoryName : repositories) {
        Repository repository = JGitUtils.createRepository(GitBlitSuite.REPOSITORIES, repositoryName, "660");
        File folder = FileKey.resolve(new File(GitBlitSuite.REPOSITORIES, repositoryName), FS.DETECTED);
        assertNotNull(repository);
        assertFalse(JGitUtils.hasCommits(repository));
        assertNull(JGitUtils.getFirstCommit(repository, null));
        assertEquals("0660", 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);
            assertEquals(0, mode & JnaUtils.S_IRWXO);
            mode = JnaUtils.getFilemode(folder.getAbsolutePath() + "/HEAD");
            assertEquals(JnaUtils.S_IRGRP | JnaUtils.S_IWGRP, mode & JnaUtils.S_IRWXG);
            assertEquals(0, mode & JnaUtils.S_IRWXO);
            mode = JnaUtils.getFilemode(folder.getAbsolutePath() + "/config");
            assertEquals(JnaUtils.S_IRGRP | JnaUtils.S_IWGRP, mode & JnaUtils.S_IRWXG);
            assertEquals(0, mode & JnaUtils.S_IRWXO);
        }
        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 37 with Repository

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

the class JGitUtilsTest method testFilesInCommit.

@Test
public void testFilesInCommit() throws Exception {
    Repository repository = GitBlitSuite.getHelloworldRepository();
    RevCommit commit = JGitUtils.getCommit(repository, "1d0c2933a4ae69c362f76797d42d6bd182d05176");
    List<PathChangeModel> paths = JGitUtils.getFilesInCommit(repository, commit);
    commit = JGitUtils.getCommit(repository, "af0e9b2891fda85afc119f04a69acf7348922830");
    List<PathChangeModel> deletions = JGitUtils.getFilesInCommit(repository, commit);
    commit = JGitUtils.getFirstCommit(repository, null);
    List<PathChangeModel> additions = JGitUtils.getFilesInCommit(repository, commit);
    List<PathChangeModel> latestChanges = JGitUtils.getFilesInCommit(repository, null);
    repository.close();
    assertTrue("No changed paths found!", paths.size() == 1);
    for (PathChangeModel path : paths) {
        assertTrue("PathChangeModel hashcode incorrect!", path.hashCode() == (path.commitId.hashCode() + path.path.hashCode()));
        assertTrue("PathChangeModel equals itself failed!", path.equals(path));
        assertFalse("PathChangeModel equals string failed!", path.equals(""));
    }
    assertEquals(ChangeType.DELETE, deletions.get(0).changeType);
    assertEquals(ChangeType.ADD, additions.get(0).changeType);
    assertTrue(latestChanges.size() > 0);
}
Also used : Repository(org.eclipse.jgit.lib.Repository) PathChangeModel(com.gitblit.models.PathModel.PathChangeModel) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Test(org.junit.Test)

Example 38 with Repository

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

the class JGitUtilsTest method testCreateRepository.

@Test
public void testCreateRepository() throws Exception {
    String[] repositories = { "NewTestRepository.git", "NewTestRepository" };
    for (String repositoryName : repositories) {
        Repository repository = JGitUtils.createRepository(GitBlitSuite.REPOSITORIES, repositoryName);
        File folder = FileKey.resolve(new File(GitBlitSuite.REPOSITORIES, repositoryName), FS.DETECTED);
        assertNotNull(repository);
        assertFalse(JGitUtils.hasCommits(repository));
        assertNull(JGitUtils.getFirstCommit(repository, null));
        assertEquals(folder.lastModified(), JGitUtils.getFirstChange(repository, null).getTime());
        assertEquals(folder.lastModified(), JGitUtils.getLastChange(repository).when.getTime());
        assertNull(JGitUtils.getCommit(repository, null));
        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 39 with Repository

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

the class JGitUtilsTest method testFilesInPath.

@Test
public void testFilesInPath() throws Exception {
    assertEquals(0, JGitUtils.getFilesInPath(null, null, null).size());
    Repository repository = GitBlitSuite.getHelloworldRepository();
    List<PathModel> files = JGitUtils.getFilesInPath(repository, null, null);
    repository.close();
    assertTrue(files.size() > 10);
}
Also used : Repository(org.eclipse.jgit.lib.Repository) PathModel(com.gitblit.models.PathModel) Test(org.junit.Test)

Example 40 with Repository

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

the class JGitUtilsTest method testRefs.

@Test
public void testRefs() throws Exception {
    Repository repository = GitBlitSuite.getJGitRepository();
    Map<ObjectId, List<RefModel>> map = JGitUtils.getAllRefs(repository);
    repository.close();
    assertTrue(map.size() > 0);
    for (Map.Entry<ObjectId, List<RefModel>> entry : map.entrySet()) {
        List<RefModel> list = entry.getValue();
        for (RefModel ref : list) {
            if (ref.displayName.equals("refs/tags/spearce-gpg-pub")) {
                assertEquals("refs/tags/spearce-gpg-pub", ref.toString());
                assertEquals("8bbde7aacf771a9afb6992434f1ae413e010c6d8", ref.getObjectId().getName());
                assertEquals("spearce@spearce.org", ref.getAuthorIdent().getEmailAddress());
                assertTrue(ref.getShortMessage().startsWith("GPG key"));
                assertTrue(ref.getFullMessage().startsWith("GPG key"));
                assertEquals(Constants.OBJ_BLOB, ref.getReferencedObjectType());
            } else if (ref.displayName.equals("refs/tags/v0.12.1")) {
                assertTrue(ref.isAnnotatedTag());
            }
        }
    }
}
Also used : Repository(org.eclipse.jgit.lib.Repository) RefModel(com.gitblit.models.RefModel) ObjectId(org.eclipse.jgit.lib.ObjectId) PlotCommitList(org.eclipse.jgit.revplot.PlotCommitList) List(java.util.List) Map(java.util.Map) 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