use of org.eclipse.jgit.lib.Repository in project gitblit by gitblit.
the class JGitUtilsTest method testRelinkBranch.
@Test
public void testRelinkBranch() throws Exception {
Repository repository = GitBlitSuite.getJGitRepository();
// create/set the branch
JGitUtils.setBranchRef(repository, "refs/heads/reftest", "3b358ce514ec655d3ff67de1430994d8428cdb04");
assertEquals(1, JGitUtils.getAllRefs(repository).get(ObjectId.fromString("3b358ce514ec655d3ff67de1430994d8428cdb04")).size());
assertEquals(null, JGitUtils.getAllRefs(repository).get(ObjectId.fromString("755dfdb40948f5c1ec79e06bde3b0a78c352f27f")));
// reset the branch
JGitUtils.setBranchRef(repository, "refs/heads/reftest", "755dfdb40948f5c1ec79e06bde3b0a78c352f27f");
assertEquals(null, JGitUtils.getAllRefs(repository).get(ObjectId.fromString("3b358ce514ec655d3ff67de1430994d8428cdb04")));
assertEquals(1, JGitUtils.getAllRefs(repository).get(ObjectId.fromString("755dfdb40948f5c1ec79e06bde3b0a78c352f27f")).size());
// delete the branch
assertTrue(JGitUtils.deleteBranchRef(repository, "refs/heads/reftest"));
repository.close();
}
use of org.eclipse.jgit.lib.Repository in project gitblit by gitblit.
the class JGitUtilsTest method testRevlog.
@Test
public void testRevlog() throws Exception {
assertTrue(JGitUtils.getRevLog(null, 0).size() == 0);
List<RevCommit> commits = JGitUtils.getRevLog(null, 10);
assertEquals(0, commits.size());
Repository repository = GitBlitSuite.getHelloworldRepository();
// get most recent 10 commits
commits = JGitUtils.getRevLog(repository, 10);
assertEquals(10, commits.size());
// test paging and offset by getting the 10th most recent commit
RevCommit lastCommit = JGitUtils.getRevLog(repository, null, 9, 1).get(0);
assertEquals(lastCommit, commits.get(9));
// grab the two most recent commits to java.java
commits = JGitUtils.getRevLog(repository, null, "java.java", 0, 2);
assertEquals(2, commits.size());
// grab the commits since 2008-07-15
commits = JGitUtils.getRevLog(repository, null, new SimpleDateFormat("yyyy-MM-dd").parse("2008-07-15"));
assertEquals(12, commits.size());
repository.close();
}
use of org.eclipse.jgit.lib.Repository in project gitblit by gitblit.
the class JGitUtilsTest method testCreateRepositorySharedSgidParent.
@Test
public void testCreateRepositorySharedSgidParent() throws Exception {
if (!JnaUtils.isWindows()) {
String repositoryAll = "NewTestRepositoryAll.git";
String repositoryUmask = "NewTestRepositoryUmask.git";
String sgidParent = "sgid";
File parent = new File(GitBlitSuite.REPOSITORIES, sgidParent);
File folder = null;
boolean parentExisted = parent.exists();
try {
if (!parentExisted) {
assertTrue("Could not create SGID parent folder.", parent.mkdir());
}
int mode = JnaUtils.getFilemode(parent);
assertTrue(mode > 0);
assertEquals(0, JnaUtils.setFilemode(parent, mode | JnaUtils.S_ISGID | JnaUtils.S_IWGRP));
Repository repository = JGitUtils.createRepository(parent, repositoryAll, "all");
folder = FileKey.resolve(new File(parent, repositoryAll), FS.DETECTED);
assertNotNull(repository);
assertEquals("2", repository.getConfig().getString("core", null, "sharedRepository"));
assertTrue(folder.exists());
mode = JnaUtils.getFilemode(folder);
assertEquals(JnaUtils.S_ISGID, mode & JnaUtils.S_ISGID);
mode = JnaUtils.getFilemode(folder.getAbsolutePath() + "/HEAD");
assertEquals(JnaUtils.S_IRGRP | JnaUtils.S_IWGRP, mode & JnaUtils.S_IRWXG);
assertEquals(JnaUtils.S_IROTH, mode & JnaUtils.S_IRWXO);
mode = JnaUtils.getFilemode(folder.getAbsolutePath() + "/config");
assertEquals(JnaUtils.S_IRGRP | JnaUtils.S_IWGRP, mode & JnaUtils.S_IRWXG);
assertEquals(JnaUtils.S_IROTH, mode & JnaUtils.S_IRWXO);
repository.close();
RepositoryCache.close(repository);
repository = JGitUtils.createRepository(parent, repositoryUmask, "umask");
folder = FileKey.resolve(new File(parent, repositoryUmask), FS.DETECTED);
assertNotNull(repository);
assertEquals(null, repository.getConfig().getString("core", null, "sharedRepository"));
assertTrue(folder.exists());
mode = JnaUtils.getFilemode(folder);
assertEquals(JnaUtils.S_ISGID, mode & JnaUtils.S_ISGID);
repository.close();
RepositoryCache.close(repository);
} finally {
FileUtils.delete(new File(parent, repositoryAll), FileUtils.RECURSIVE | FileUtils.IGNORE_ERRORS);
FileUtils.delete(new File(parent, repositoryUmask), FileUtils.RECURSIVE | FileUtils.IGNORE_ERRORS);
if (!parentExisted) {
FileUtils.delete(parent, FileUtils.RECURSIVE | FileUtils.IGNORE_ERRORS);
}
}
}
}
use of org.eclipse.jgit.lib.Repository in project gitblit by gitblit.
the class JGitUtilsTest method testFilesInPath2.
@Test
public void testFilesInPath2() throws Exception {
assertEquals(0, JGitUtils.getFilesInPath2(null, null, null).size());
Repository repository = GitBlitSuite.getHelloworldRepository();
List<PathModel> files = JGitUtils.getFilesInPath2(repository, null, null);
repository.close();
assertTrue(files.size() > 10);
}
use of org.eclipse.jgit.lib.Repository in project gitblit by gitblit.
the class LuceneExecutorTest method testQuery.
@Test
public void testQuery() throws Exception {
// 2 occurrences on the master branch
Repository repository = GitBlitSuite.getHelloworldRepository();
RepositoryModel model = newRepositoryModel(repository);
repository.close();
List<SearchResult> results = lucene.search("ada", 1, 10, model.name);
assertEquals(2, results.size());
for (SearchResult res : results) {
assertEquals("refs/heads/master", res.branch);
}
// author test
results = lucene.search("author: tinogomes AND type:commit", 1, 10, model.name);
assertEquals(2, results.size());
// blob test
results = lucene.search("type: blob AND \"import std.stdio\"", 1, 10, model.name);
assertEquals(1, results.size());
assertEquals("d.D", results.get(0).path);
// commit test
repository = GitBlitSuite.getJGitRepository();
model = newRepositoryModel(repository);
repository.close();
results = lucene.search("\"initial jgit contribution to eclipse.org\"", 1, 10, model.name);
assertEquals(1, results.size());
assertEquals("Git Development Community", results.get(0).author);
assertEquals("1a6964c8274c50f0253db75f010d78ef0e739343", results.get(0).commitId);
assertEquals("refs/heads/master", results.get(0).branch);
// hash id tests
results = lucene.search("type:commit AND commit:1a6964c8274c50f0253db75f010d78ef0e739343", 1, 10, model.name);
assertEquals(1, results.size());
results = lucene.search("type:commit AND commit:1a6964c8274*", 1, 10, model.name);
assertEquals("Shawn O. Pearce", results.get(0).committer);
assertEquals(1, results.size());
// annotated tag test
results = lucene.search("I663208919f297836a9c16bf458e4a43ffaca4c12", 1, 10, model.name);
assertEquals(1, results.size());
assertEquals("[v1.3.0.201202151440-r]", results.get(0).tags.toString());
}
Aggregations