Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. package com.gitblit.tests;
  2. import java.io.File;
  3. import java.util.Date;
  4. import java.util.List;
  5. import junit.framework.TestCase;
  6. import org.eclipse.jgit.lib.Constants;
  7. import org.eclipse.jgit.lib.Repository;
  8. import org.eclipse.jgit.revwalk.RevBlob;
  9. import org.eclipse.jgit.revwalk.RevCommit;
  10. import org.eclipse.jgit.revwalk.RevObject;
  11. import org.eclipse.jgit.revwalk.RevTree;
  12. import org.eclipse.jgit.storage.file.FileRepository;
  13. import com.gitblit.utils.JGitUtils;
  14. import com.gitblit.wicket.models.PathModel;
  15. import com.gitblit.wicket.models.RefModel;
  16. import com.gitblit.wicket.models.TicGitTicket;
  17. public class JGitUtilsTest extends TestCase {
  18. private File repositoriesFolder = new File("c:/projects/git");
  19. private boolean exportAll = true;
  20. private boolean readNested = true;
  21. private List<String> getRepositories() {
  22. return JGitUtils.getRepositoryList(repositoriesFolder, exportAll, readNested);
  23. }
  24. private Repository getRepository() throws Exception {
  25. return new FileRepository(new File(repositoriesFolder, getRepositories().get(0)) + "/" + Constants.DOT_GIT);
  26. }
  27. public void testFindRepositories() {
  28. List<String> list = getRepositories();
  29. assertTrue("No repositories found in " + repositoriesFolder, list.size() > 0);
  30. }
  31. public void testOpenRepository() throws Exception {
  32. Repository r = getRepository();
  33. r.close();
  34. assertTrue("Could not find repository!", r != null);
  35. }
  36. public void testLastChangeRepository() throws Exception {
  37. Repository r = getRepository();
  38. Date date = JGitUtils.getLastChange(r);
  39. r.close();
  40. assertTrue("Could not get last repository change date!", date != null);
  41. }
  42. public void testRetrieveRevObject() throws Exception {
  43. Repository r = getRepository();
  44. RevCommit commit = JGitUtils.getCommit(r, Constants.HEAD);
  45. RevTree tree = commit.getTree();
  46. RevObject object = JGitUtils.getRevObject(r, tree, "AUTHORS");
  47. r.close();
  48. assertTrue("Object is null!", object != null);
  49. }
  50. public void testRetrieveStringContent() throws Exception {
  51. Repository r = getRepository();
  52. RevCommit commit = JGitUtils.getCommit(r, Constants.HEAD);
  53. RevTree tree = commit.getTree();
  54. RevBlob blob = (RevBlob) JGitUtils.getRevObject(r, tree, "AUTHORS");
  55. String content = JGitUtils.getRawContentAsString(r, blob);
  56. r.close();
  57. assertTrue("Content is null!", content != null);
  58. }
  59. public void testTicGit() throws Exception {
  60. Repository r = new FileRepository(new File(repositoriesFolder, "ticgit") + "/" + Constants.DOT_GIT);
  61. RefModel ticgit = JGitUtils.getTicGitBranch(r);
  62. assertTrue("Ticgit branch does not exist!", ticgit != null);
  63. List<TicGitTicket> tickets = JGitUtils.getTicGitTickets(r);
  64. assertTrue("No tickets found!", tickets.size() > 0);
  65. r.close();
  66. }
  67. public void testFilesInCommit() throws Exception {
  68. Repository r = getRepository();
  69. RevCommit commit = JGitUtils.getCommit(r, Constants.HEAD);
  70. List<PathModel> paths = JGitUtils.getFilesInCommit(r, commit);
  71. r.close();
  72. assertTrue("No changed paths found!", paths.size() > 0);
  73. }
  74. public void testCommitDiff() throws Exception {
  75. Repository r = getRepository();
  76. RevCommit commit = JGitUtils.getCommit(r, Constants.HEAD);
  77. String diff = JGitUtils.getCommitDiff(r, commit, false);
  78. r.close();
  79. System.out.println(diff);
  80. }
  81. }