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