| | |
| | | import org.eclipse.jgit.lib.ObjectId;
|
| | | import org.eclipse.jgit.lib.PersonIdent;
|
| | | import org.eclipse.jgit.lib.Repository;
|
| | | import org.eclipse.jgit.lib.RepositoryCache;
|
| | | import org.eclipse.jgit.lib.RepositoryCache.FileKey;
|
| | | import org.eclipse.jgit.revwalk.RevCommit;
|
| | | import org.eclipse.jgit.revwalk.RevTree;
|
| | | import org.eclipse.jgit.util.FS;
|
| | | import org.eclipse.jgit.util.FileUtils;
|
| | | import org.junit.Test;
|
| | |
| | |
|
| | | @Test
|
| | | public void testFindRepositories() {
|
| | | List<String> list = JGitUtils.getRepositoryList(null, true, true);
|
| | | List<String> list = JGitUtils.getRepositoryList(null, false, true, -1, null);
|
| | | assertEquals(0, list.size());
|
| | | list.addAll(JGitUtils.getRepositoryList(new File("DoesNotExist"), true, true));
|
| | | list.addAll(JGitUtils.getRepositoryList(new File("DoesNotExist"), true, true, -1, null));
|
| | | assertEquals(0, list.size());
|
| | | list.addAll(JGitUtils.getRepositoryList(GitBlitSuite.REPOSITORIES, true, true));
|
| | | list.addAll(JGitUtils.getRepositoryList(GitBlitSuite.REPOSITORIES, false, true, -1, null));
|
| | | assertTrue("No repositories found in " + GitBlitSuite.REPOSITORIES, list.size() > 0);
|
| | | }
|
| | |
|
| | | @Test
|
| | | public void testFindExclusions() {
|
| | | List<String> list = JGitUtils.getRepositoryList(GitBlitSuite.REPOSITORIES, false, true, -1, null);
|
| | | assertTrue("Missing jgit repository?!", list.contains("test/jgit.git"));
|
| | |
|
| | | list = JGitUtils.getRepositoryList(GitBlitSuite.REPOSITORIES, false, true, -1, Arrays.asList("test/jgit\\.git"));
|
| | | assertFalse("Repository exclusion failed!", list.contains("test/jgit.git"));
|
| | |
|
| | | list = JGitUtils.getRepositoryList(GitBlitSuite.REPOSITORIES, false, true, -1, Arrays.asList("test/*"));
|
| | | assertFalse("Repository exclusion failed!", list.contains("test/jgit.git"));
|
| | |
|
| | | list = JGitUtils.getRepositoryList(GitBlitSuite.REPOSITORIES, false, true, -1, Arrays.asList(".*jgit.*"));
|
| | | assertFalse("Repository exclusion failed!", list.contains("test/jgit.git"));
|
| | | assertFalse("Repository exclusion failed!", list.contains("working/jgit"));
|
| | | assertFalse("Repository exclusion failed!", list.contains("working/jgit2"));
|
| | |
|
| | | }
|
| | |
|
| | | @Test
|
| | |
| | |
|
| | | @Test
|
| | | public void testLastCommit() throws Exception {
|
| | | assertEquals(new Date(0), JGitUtils.getLastChange(null, null));
|
| | | assertEquals(new Date(0), JGitUtils.getLastChange(null));
|
| | |
|
| | | Repository repository = GitBlitSuite.getHelloworldRepository();
|
| | | assertTrue(JGitUtils.getCommit(repository, null) != null);
|
| | | Date date = JGitUtils.getLastChange(repository, null);
|
| | | Date date = JGitUtils.getLastChange(repository);
|
| | | repository.close();
|
| | | assertNotNull("Could not get last repository change date!", date);
|
| | | }
|
| | |
| | | assertNull(JGitUtils.getFirstCommit(repository, null));
|
| | | assertEquals(folder.lastModified(), JGitUtils.getFirstChange(repository, null)
|
| | | .getTime());
|
| | | assertEquals(folder.lastModified(), JGitUtils.getLastChange(repository, null).getTime());
|
| | | assertEquals(folder.lastModified(), JGitUtils.getLastChange(repository).getTime());
|
| | | assertNull(JGitUtils.getCommit(repository, null));
|
| | | repository.close();
|
| | | assertTrue(GitBlit.self().deleteRepository(repositoryName));
|
| | | RepositoryCache.close(repository);
|
| | | FileUtils.delete(repository.getDirectory(), FileUtils.RECURSIVE);
|
| | | }
|
| | | }
|
| | |
|
| | |
| | | }
|
| | | repository.close();
|
| | |
|
| | | repository = GitBlitSuite.getBluezGnomeRepository();
|
| | | repository = GitBlitSuite.getGitectiveRepository();
|
| | | for (RefModel model : JGitUtils.getTags(repository, true, -1)) {
|
| | | if (model.getObjectId().getName().equals("728643ec0c438c77e182898c2f2967dbfdc231c8")) {
|
| | | if (model.getObjectId().getName().equals("035254295a9bba11f72b1f9d6791a6b957abee7b")) {
|
| | | assertFalse(model.isAnnotatedTag());
|
| | | assertTrue(model.getAuthorIdent().getEmailAddress().equals("marcel@holtmann.org"));
|
| | | assertEquals("Update changelog and bump version number\n", model.getFullMessage());
|
| | | assertTrue(model.getAuthorIdent().getEmailAddress().equals("kevinsawicki@gmail.com"));
|
| | | assertEquals("Add scm and issue tracker elements to pom.xml\n", model.getFullMessage());
|
| | | }
|
| | | }
|
| | | repository.close();
|
| | |
| | | assertEquals("183474d554e6f68478a02d9d7888b67a9338cdff", list.get(0).notesRef
|
| | | .getReferencedObjectId().getName());
|
| | | }
|
| | | |
| | | @Test
|
| | | public void testRelinkHEAD() throws Exception {
|
| | | Repository repository = GitBlitSuite.getJGitRepository();
|
| | | // confirm HEAD is master
|
| | | String currentRef = JGitUtils.getHEADRef(repository);
|
| | | assertEquals("refs/heads/master", currentRef);
|
| | | List<String> availableHeads = JGitUtils.getAvailableHeadTargets(repository);
|
| | | assertTrue(availableHeads.size() > 0);
|
| | | |
| | | // set HEAD to stable-1.2
|
| | | JGitUtils.setHEADtoRef(repository, "refs/heads/stable-1.2");
|
| | | currentRef = JGitUtils.getHEADRef(repository);
|
| | | assertEquals("refs/heads/stable-1.2", currentRef);
|
| | |
|
| | | // restore HEAD to master
|
| | | JGitUtils.setHEADtoRef(repository, "refs/heads/master");
|
| | | currentRef = JGitUtils.getHEADRef(repository);
|
| | | assertEquals("refs/heads/master", currentRef);
|
| | | |
| | | repository.close();
|
| | | }
|
| | |
|
| | | @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();
|
| | | }
|
| | |
|
| | | @Test
|
| | | public void testCreateOrphanedBranch() throws Exception {
|
| | | Repository repository = JGitUtils.createRepository(GitBlitSuite.REPOSITORIES, "orphantest");
|
| | | assertTrue(JGitUtils.createOrphanBranch(repository,
|
| | | "x" + Long.toHexString(System.currentTimeMillis()).toUpperCase()));
|
| | | FileUtils.delete(repository.getDirectory(), FileUtils.RECURSIVE);
|
| | | "x" + Long.toHexString(System.currentTimeMillis()).toUpperCase(), null));
|
| | | FileUtils.delete(repository.getDirectory(), FileUtils.RECURSIVE);
|
| | | }
|
| | |
|
| | | @Test
|
| | | public void testStringContent() throws Exception {
|
| | | Repository repository = GitBlitSuite.getHelloworldRepository();
|
| | | String contentA = JGitUtils.getStringContent(repository, null, "java.java");
|
| | | String contentA = JGitUtils.getStringContent(repository, (RevTree) null, "java.java");
|
| | | RevCommit commit = JGitUtils.getCommit(repository, Constants.HEAD);
|
| | | String contentB = JGitUtils.getStringContent(repository, commit.getTree(), "java.java");
|
| | | String contentC = JGitUtils.getStringContent(repository, commit.getTree(), "missing.txt");
|
| | |
| | | assertEquals("-rwxr-xr-x",
|
| | | JGitUtils.getPermissionsFromMode(FileMode.EXECUTABLE_FILE.getBits()));
|
| | | assertEquals("symlink", JGitUtils.getPermissionsFromMode(FileMode.SYMLINK.getBits()));
|
| | | assertEquals("gitlink", JGitUtils.getPermissionsFromMode(FileMode.GITLINK.getBits()));
|
| | | assertEquals("submodule", JGitUtils.getPermissionsFromMode(FileMode.GITLINK.getBits()));
|
| | | assertEquals("missing", JGitUtils.getPermissionsFromMode(FileMode.MISSING.getBits()));
|
| | | }
|
| | |
|