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);
}
}
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);
}
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);
}
}
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);
}
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());
}
}
}
}
Aggregations