commit | author | age
|
2a7306
|
1 |
/*
|
JM |
2 |
* Copyright 2011 gitblit.com.
|
|
3 |
*
|
|
4 |
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5 |
* you may not use this file except in compliance with the License.
|
|
6 |
* You may obtain a copy of the License at
|
|
7 |
*
|
|
8 |
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9 |
*
|
|
10 |
* Unless required by applicable law or agreed to in writing, software
|
|
11 |
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13 |
* See the License for the specific language governing permissions and
|
|
14 |
* limitations under the License.
|
|
15 |
*/
|
|
16 |
package com.gitblit.tests;
|
|
17 |
|
7e8873
|
18 |
import static org.junit.Assert.assertEquals;
|
JM |
19 |
import static org.junit.Assert.assertFalse;
|
|
20 |
import static org.junit.Assert.assertNotNull;
|
|
21 |
import static org.junit.Assert.assertNull;
|
|
22 |
import static org.junit.Assert.assertTrue;
|
|
23 |
|
2a7306
|
24 |
import java.io.File;
|
JM |
25 |
import java.io.FileOutputStream;
|
2f1c77
|
26 |
import java.text.SimpleDateFormat;
|
a125cf
|
27 |
import java.util.Arrays;
|
2a7306
|
28 |
import java.util.Date;
|
JM |
29 |
import java.util.List;
|
a125cf
|
30 |
import java.util.Map;
|
2a7306
|
31 |
|
a125cf
|
32 |
import org.eclipse.jgit.diff.DiffEntry.ChangeType;
|
2a7306
|
33 |
import org.eclipse.jgit.lib.Constants;
|
a125cf
|
34 |
import org.eclipse.jgit.lib.FileMode;
|
JM |
35 |
import org.eclipse.jgit.lib.ObjectId;
|
|
36 |
import org.eclipse.jgit.lib.PersonIdent;
|
2a7306
|
37 |
import org.eclipse.jgit.lib.Repository;
|
168566
|
38 |
import org.eclipse.jgit.lib.RepositoryCache.FileKey;
|
2a7306
|
39 |
import org.eclipse.jgit.revwalk.RevCommit;
|
ae9e15
|
40 |
import org.eclipse.jgit.revwalk.RevTree;
|
168566
|
41 |
import org.eclipse.jgit.util.FS;
|
a2709d
|
42 |
import org.eclipse.jgit.util.FileUtils;
|
7e8873
|
43 |
import org.junit.Test;
|
2a7306
|
44 |
|
7e8873
|
45 |
import com.gitblit.Constants.SearchType;
|
f1720c
|
46 |
import com.gitblit.GitBlit;
|
a125cf
|
47 |
import com.gitblit.Keys;
|
4ab184
|
48 |
import com.gitblit.models.GitNote;
|
a125cf
|
49 |
import com.gitblit.models.PathModel;
|
1f9dae
|
50 |
import com.gitblit.models.PathModel.PathChangeModel;
|
JM |
51 |
import com.gitblit.models.RefModel;
|
2a7306
|
52 |
import com.gitblit.utils.JGitUtils;
|
4ab184
|
53 |
import com.gitblit.utils.StringUtils;
|
2a7306
|
54 |
|
7e8873
|
55 |
public class JGitUtilsTest {
|
a125cf
|
56 |
|
7e8873
|
57 |
@Test
|
a125cf
|
58 |
public void testDisplayName() throws Exception {
|
7e8873
|
59 |
assertEquals("Napoleon Bonaparte",
|
JM |
60 |
JGitUtils.getDisplayName(new PersonIdent("Napoleon Bonaparte", "")));
|
|
61 |
assertEquals("<someone@somewhere.com>",
|
|
62 |
JGitUtils.getDisplayName(new PersonIdent("", "someone@somewhere.com")));
|
|
63 |
assertEquals("Napoleon Bonaparte <someone@somewhere.com>",
|
|
64 |
JGitUtils.getDisplayName(new PersonIdent("Napoleon Bonaparte",
|
|
65 |
"someone@somewhere.com")));
|
a125cf
|
66 |
}
|
2a7306
|
67 |
|
7e8873
|
68 |
@Test
|
2a7306
|
69 |
public void testFindRepositories() {
|
b86562
|
70 |
List<String> list = JGitUtils.getRepositoryList(null, false, true);
|
7e8873
|
71 |
assertEquals(0, list.size());
|
f1720c
|
72 |
list.addAll(JGitUtils.getRepositoryList(new File("DoesNotExist"), true, true));
|
7e8873
|
73 |
assertEquals(0, list.size());
|
236001
|
74 |
list.addAll(JGitUtils.getRepositoryList(GitBlitSuite.REPOSITORIES, false, true));
|
2a7306
|
75 |
assertTrue("No repositories found in " + GitBlitSuite.REPOSITORIES, list.size() > 0);
|
JM |
76 |
}
|
|
77 |
|
7e8873
|
78 |
@Test
|
2a7306
|
79 |
public void testOpenRepository() throws Exception {
|
JM |
80 |
Repository repository = GitBlitSuite.getHelloworldRepository();
|
|
81 |
repository.close();
|
7e8873
|
82 |
assertNotNull("Could not find repository!", repository);
|
2a7306
|
83 |
}
|
JM |
84 |
|
7e8873
|
85 |
@Test
|
2a7306
|
86 |
public void testFirstCommit() throws Exception {
|
7e8873
|
87 |
assertEquals(new Date(0), JGitUtils.getFirstChange(null, null));
|
a125cf
|
88 |
|
2a7306
|
89 |
Repository repository = GitBlitSuite.getHelloworldRepository();
|
JM |
90 |
RevCommit commit = JGitUtils.getFirstCommit(repository, null);
|
db653a
|
91 |
Date firstChange = JGitUtils.getFirstChange(repository, null);
|
2a7306
|
92 |
repository.close();
|
7e8873
|
93 |
assertNotNull("Could not get first commit!", commit);
|
JM |
94 |
assertEquals("Incorrect first commit!", "f554664a346629dc2b839f7292d06bad2db4aece",
|
|
95 |
commit.getName());
|
db653a
|
96 |
assertTrue(firstChange.equals(new Date(commit.getCommitTime() * 1000L)));
|
f1720c
|
97 |
}
|
a125cf
|
98 |
|
7e8873
|
99 |
@Test
|
f1720c
|
100 |
public void testLastCommit() throws Exception {
|
4fea45
|
101 |
assertEquals(new Date(0), JGitUtils.getLastChange(null));
|
a125cf
|
102 |
|
f1720c
|
103 |
Repository repository = GitBlitSuite.getHelloworldRepository();
|
JM |
104 |
assertTrue(JGitUtils.getCommit(repository, null) != null);
|
4fea45
|
105 |
Date date = JGitUtils.getLastChange(repository);
|
f1720c
|
106 |
repository.close();
|
7e8873
|
107 |
assertNotNull("Could not get last repository change date!", date);
|
f1720c
|
108 |
}
|
JM |
109 |
|
7e8873
|
110 |
@Test
|
f1720c
|
111 |
public void testCreateRepository() throws Exception {
|
JM |
112 |
String[] repositories = { "NewTestRepository.git", "NewTestRepository" };
|
008322
|
113 |
for (String repositoryName : repositories) {
|
f1720c
|
114 |
Repository repository = JGitUtils.createRepository(GitBlitSuite.REPOSITORIES,
|
168566
|
115 |
repositoryName);
|
008322
|
116 |
File folder = FileKey.resolve(new File(GitBlitSuite.REPOSITORIES, repositoryName),
|
JM |
117 |
FS.DETECTED);
|
7e8873
|
118 |
assertNotNull(repository);
|
f1720c
|
119 |
assertFalse(JGitUtils.hasCommits(repository));
|
7e8873
|
120 |
assertNull(JGitUtils.getFirstCommit(repository, null));
|
JM |
121 |
assertEquals(folder.lastModified(), JGitUtils.getFirstChange(repository, null)
|
|
122 |
.getTime());
|
4fea45
|
123 |
assertEquals(folder.lastModified(), JGitUtils.getLastChange(repository).getTime());
|
7e8873
|
124 |
assertNull(JGitUtils.getCommit(repository, null));
|
f1720c
|
125 |
repository.close();
|
JM |
126 |
assertTrue(GitBlit.self().deleteRepository(repositoryName));
|
|
127 |
}
|
2a7306
|
128 |
}
|
JM |
129 |
|
7e8873
|
130 |
@Test
|
28d6b2
|
131 |
public void testRefs() throws Exception {
|
4ab184
|
132 |
Repository repository = GitBlitSuite.getJGitRepository();
|
JM |
133 |
Map<ObjectId, List<RefModel>> map = JGitUtils.getAllRefs(repository);
|
a125cf
|
134 |
repository.close();
|
JM |
135 |
assertTrue(map.size() > 0);
|
4ab184
|
136 |
for (Map.Entry<ObjectId, List<RefModel>> entry : map.entrySet()) {
|
JM |
137 |
List<RefModel> list = entry.getValue();
|
|
138 |
for (RefModel ref : list) {
|
|
139 |
if (ref.displayName.equals("refs/tags/spearce-gpg-pub")) {
|
7e8873
|
140 |
assertEquals("refs/tags/spearce-gpg-pub", ref.toString());
|
JM |
141 |
assertEquals("8bbde7aacf771a9afb6992434f1ae413e010c6d8", ref.getObjectId()
|
|
142 |
.getName());
|
|
143 |
assertEquals("spearce@spearce.org", ref.getAuthorIdent().getEmailAddress());
|
4ab184
|
144 |
assertTrue(ref.getShortMessage().startsWith("GPG key"));
|
008322
|
145 |
assertTrue(ref.getFullMessage().startsWith("GPG key"));
|
7e8873
|
146 |
assertEquals(Constants.OBJ_BLOB, ref.getReferencedObjectType());
|
4ab184
|
147 |
} else if (ref.displayName.equals("refs/tags/v0.12.1")) {
|
JM |
148 |
assertTrue(ref.isAnnotatedTag());
|
|
149 |
}
|
|
150 |
}
|
|
151 |
}
|
a125cf
|
152 |
}
|
JM |
153 |
|
7e8873
|
154 |
@Test
|
a125cf
|
155 |
public void testBranches() throws Exception {
|
168566
|
156 |
Repository repository = GitBlitSuite.getJGitRepository();
|
85c2e6
|
157 |
assertTrue(JGitUtils.getLocalBranches(repository, true, 0).size() == 0);
|
5cc4f2
|
158 |
for (RefModel model : JGitUtils.getLocalBranches(repository, true, -1)) {
|
28d6b2
|
159 |
assertTrue(model.getName().startsWith(Constants.R_HEADS));
|
JM |
160 |
assertTrue(model.equals(model));
|
|
161 |
assertFalse(model.equals(""));
|
4ab184
|
162 |
assertTrue(model.hashCode() == model.getReferencedObjectId().hashCode()
|
28d6b2
|
163 |
+ model.getName().hashCode());
|
4ab184
|
164 |
assertTrue(model.getShortMessage().equals(model.getShortMessage()));
|
28d6b2
|
165 |
}
|
5cc4f2
|
166 |
for (RefModel model : JGitUtils.getRemoteBranches(repository, true, -1)) {
|
28d6b2
|
167 |
assertTrue(model.getName().startsWith(Constants.R_REMOTES));
|
JM |
168 |
assertTrue(model.equals(model));
|
|
169 |
assertFalse(model.equals(""));
|
4ab184
|
170 |
assertTrue(model.hashCode() == model.getReferencedObjectId().hashCode()
|
28d6b2
|
171 |
+ model.getName().hashCode());
|
4ab184
|
172 |
assertTrue(model.getShortMessage().equals(model.getShortMessage()));
|
28d6b2
|
173 |
}
|
168566
|
174 |
assertTrue(JGitUtils.getRemoteBranches(repository, true, 8).size() == 8);
|
a125cf
|
175 |
repository.close();
|
JM |
176 |
}
|
|
177 |
|
7e8873
|
178 |
@Test
|
a125cf
|
179 |
public void testTags() throws Exception {
|
168566
|
180 |
Repository repository = GitBlitSuite.getJGitRepository();
|
85c2e6
|
181 |
assertTrue(JGitUtils.getTags(repository, true, 5).size() == 5);
|
5cc4f2
|
182 |
for (RefModel model : JGitUtils.getTags(repository, true, -1)) {
|
168566
|
183 |
if (model.getObjectId().getName().equals("d28091fb2977077471138fe97da1440e0e8ae0da")) {
|
28d6b2
|
184 |
assertTrue("Not an annotated tag!", model.isAnnotatedTag());
|
JM |
185 |
}
|
|
186 |
assertTrue(model.getName().startsWith(Constants.R_TAGS));
|
|
187 |
assertTrue(model.equals(model));
|
|
188 |
assertFalse(model.equals(""));
|
4ab184
|
189 |
assertTrue(model.hashCode() == model.getReferencedObjectId().hashCode()
|
28d6b2
|
190 |
+ model.getName().hashCode());
|
4ab184
|
191 |
}
|
JM |
192 |
repository.close();
|
008322
|
193 |
|
d3065f
|
194 |
repository = GitBlitSuite.getGitectiveRepository();
|
5cc4f2
|
195 |
for (RefModel model : JGitUtils.getTags(repository, true, -1)) {
|
d3065f
|
196 |
if (model.getObjectId().getName().equals("035254295a9bba11f72b1f9d6791a6b957abee7b")) {
|
4ab184
|
197 |
assertFalse(model.isAnnotatedTag());
|
d3065f
|
198 |
assertTrue(model.getAuthorIdent().getEmailAddress().equals("kevinsawicki@gmail.com"));
|
JM |
199 |
assertEquals("Add scm and issue tracker elements to pom.xml\n", model.getFullMessage());
|
4ab184
|
200 |
}
|
28d6b2
|
201 |
}
|
JM |
202 |
repository.close();
|
|
203 |
}
|
|
204 |
|
7e8873
|
205 |
@Test
|
a125cf
|
206 |
public void testCommitNotes() throws Exception {
|
4ab184
|
207 |
Repository repository = GitBlitSuite.getJGitRepository();
|
JM |
208 |
RevCommit commit = JGitUtils.getCommit(repository,
|
|
209 |
"690c268c793bfc218982130fbfc25870f292295e");
|
|
210 |
List<GitNote> list = JGitUtils.getNotesOnCommit(repository, commit);
|
|
211 |
repository.close();
|
|
212 |
assertTrue(list.size() > 0);
|
7e8873
|
213 |
assertEquals("183474d554e6f68478a02d9d7888b67a9338cdff", list.get(0).notesRef
|
JM |
214 |
.getReferencedObjectId().getName());
|
2a7306
|
215 |
}
|
90b8d7
|
216 |
|
JM |
217 |
@Test
|
|
218 |
public void testRelinkHEAD() throws Exception {
|
|
219 |
Repository repository = GitBlitSuite.getJGitRepository();
|
|
220 |
// confirm HEAD is master
|
|
221 |
String currentRef = JGitUtils.getHEADRef(repository);
|
|
222 |
assertEquals("refs/heads/master", currentRef);
|
|
223 |
List<String> availableHeads = JGitUtils.getAvailableHeadTargets(repository);
|
|
224 |
assertTrue(availableHeads.size() > 0);
|
|
225 |
|
|
226 |
// set HEAD to stable-1.2
|
|
227 |
JGitUtils.setHEADtoRef(repository, "refs/heads/stable-1.2");
|
|
228 |
currentRef = JGitUtils.getHEADRef(repository);
|
|
229 |
assertEquals("refs/heads/stable-1.2", currentRef);
|
|
230 |
|
|
231 |
// restore HEAD to master
|
|
232 |
JGitUtils.setHEADtoRef(repository, "refs/heads/master");
|
|
233 |
currentRef = JGitUtils.getHEADRef(repository);
|
|
234 |
assertEquals("refs/heads/master", currentRef);
|
|
235 |
|
|
236 |
repository.close();
|
|
237 |
}
|
2a7306
|
238 |
|
7e8873
|
239 |
@Test
|
f96d32
|
240 |
public void testRelinkBranch() throws Exception {
|
JM |
241 |
Repository repository = GitBlitSuite.getJGitRepository();
|
|
242 |
|
|
243 |
// create/set the branch
|
|
244 |
JGitUtils.setBranchRef(repository, "refs/heads/reftest", "3b358ce514ec655d3ff67de1430994d8428cdb04");
|
|
245 |
assertEquals(1, JGitUtils.getAllRefs(repository).get(ObjectId.fromString("3b358ce514ec655d3ff67de1430994d8428cdb04")).size());
|
|
246 |
assertEquals(null, JGitUtils.getAllRefs(repository).get(ObjectId.fromString("755dfdb40948f5c1ec79e06bde3b0a78c352f27f")));
|
|
247 |
|
|
248 |
// reset the branch
|
|
249 |
JGitUtils.setBranchRef(repository, "refs/heads/reftest", "755dfdb40948f5c1ec79e06bde3b0a78c352f27f");
|
|
250 |
assertEquals(null, JGitUtils.getAllRefs(repository).get(ObjectId.fromString("3b358ce514ec655d3ff67de1430994d8428cdb04")));
|
|
251 |
assertEquals(1, JGitUtils.getAllRefs(repository).get(ObjectId.fromString("755dfdb40948f5c1ec79e06bde3b0a78c352f27f")).size());
|
|
252 |
|
|
253 |
// delete the branch
|
|
254 |
assertTrue(JGitUtils.deleteBranchRef(repository, "refs/heads/reftest"));
|
|
255 |
repository.close();
|
|
256 |
}
|
|
257 |
|
|
258 |
@Test
|
a2709d
|
259 |
public void testCreateOrphanedBranch() throws Exception {
|
671c19
|
260 |
Repository repository = JGitUtils.createRepository(GitBlitSuite.REPOSITORIES, "orphantest");
|
a2709d
|
261 |
assertTrue(JGitUtils.createOrphanBranch(repository,
|
7b0895
|
262 |
"x" + Long.toHexString(System.currentTimeMillis()).toUpperCase(), null));
|
JM |
263 |
FileUtils.delete(repository.getDirectory(), FileUtils.RECURSIVE);
|
a2709d
|
264 |
}
|
JM |
265 |
|
7e8873
|
266 |
@Test
|
a125cf
|
267 |
public void testStringContent() throws Exception {
|
2a7306
|
268 |
Repository repository = GitBlitSuite.getHelloworldRepository();
|
ae9e15
|
269 |
String contentA = JGitUtils.getStringContent(repository, (RevTree) null, "java.java");
|
2a7306
|
270 |
RevCommit commit = JGitUtils.getCommit(repository, Constants.HEAD);
|
4ab184
|
271 |
String contentB = JGitUtils.getStringContent(repository, commit.getTree(), "java.java");
|
JM |
272 |
String contentC = JGitUtils.getStringContent(repository, commit.getTree(), "missing.txt");
|
|
273 |
|
|
274 |
// manually construct a blob, calculate the hash, lookup the hash in git
|
|
275 |
StringBuilder sb = new StringBuilder();
|
|
276 |
sb.append("blob ").append(contentA.length()).append('\0');
|
|
277 |
sb.append(contentA);
|
|
278 |
String sha1 = StringUtils.getSHA1(sb.toString());
|
|
279 |
String contentD = JGitUtils.getStringContent(repository, sha1);
|
2a7306
|
280 |
repository.close();
|
a125cf
|
281 |
assertTrue("ContentA is null!", contentA != null && contentA.length() > 0);
|
JM |
282 |
assertTrue("ContentB is null!", contentB != null && contentB.length() > 0);
|
|
283 |
assertTrue(contentA.equals(contentB));
|
7e8873
|
284 |
assertNull(contentC);
|
4ab184
|
285 |
assertTrue(contentA.equals(contentD));
|
2a7306
|
286 |
}
|
JM |
287 |
|
7e8873
|
288 |
@Test
|
2a7306
|
289 |
public void testFilesInCommit() throws Exception {
|
JM |
290 |
Repository repository = GitBlitSuite.getHelloworldRepository();
|
|
291 |
RevCommit commit = JGitUtils.getCommit(repository,
|
|
292 |
"1d0c2933a4ae69c362f76797d42d6bd182d05176");
|
|
293 |
List<PathChangeModel> paths = JGitUtils.getFilesInCommit(repository, commit);
|
a125cf
|
294 |
|
JM |
295 |
commit = JGitUtils.getCommit(repository, "af0e9b2891fda85afc119f04a69acf7348922830");
|
|
296 |
List<PathChangeModel> deletions = JGitUtils.getFilesInCommit(repository, commit);
|
|
297 |
|
|
298 |
commit = JGitUtils.getFirstCommit(repository, null);
|
|
299 |
List<PathChangeModel> additions = JGitUtils.getFilesInCommit(repository, commit);
|
|
300 |
|
|
301 |
List<PathChangeModel> latestChanges = JGitUtils.getFilesInCommit(repository, null);
|
|
302 |
|
2a7306
|
303 |
repository.close();
|
JM |
304 |
assertTrue("No changed paths found!", paths.size() == 1);
|
28d6b2
|
305 |
for (PathChangeModel path : paths) {
|
JM |
306 |
assertTrue("PathChangeModel hashcode incorrect!",
|
|
307 |
path.hashCode() == (path.commitId.hashCode() + path.path.hashCode()));
|
|
308 |
assertTrue("PathChangeModel equals itself failed!", path.equals(path));
|
|
309 |
assertFalse("PathChangeModel equals string failed!", path.equals(""));
|
|
310 |
}
|
7e8873
|
311 |
assertEquals(ChangeType.DELETE, deletions.get(0).changeType);
|
JM |
312 |
assertEquals(ChangeType.ADD, additions.get(0).changeType);
|
a125cf
|
313 |
assertTrue(latestChanges.size() > 0);
|
JM |
314 |
}
|
|
315 |
|
7e8873
|
316 |
@Test
|
a125cf
|
317 |
public void testFilesInPath() throws Exception {
|
7e8873
|
318 |
assertEquals(0, JGitUtils.getFilesInPath(null, null, null).size());
|
a125cf
|
319 |
Repository repository = GitBlitSuite.getHelloworldRepository();
|
JM |
320 |
List<PathModel> files = JGitUtils.getFilesInPath(repository, null, null);
|
|
321 |
repository.close();
|
|
322 |
assertTrue(files.size() > 10);
|
|
323 |
}
|
|
324 |
|
7e8873
|
325 |
@Test
|
a125cf
|
326 |
public void testDocuments() throws Exception {
|
JM |
327 |
Repository repository = GitBlitSuite.getTicgitRepository();
|
|
328 |
List<String> extensions = GitBlit.getStrings(Keys.web.markdownExtensions);
|
|
329 |
List<PathModel> markdownDocs = JGitUtils.getDocuments(repository, extensions);
|
|
330 |
List<PathModel> markdownDocs2 = JGitUtils.getDocuments(repository,
|
|
331 |
Arrays.asList(new String[] { ".mkd", ".md" }));
|
|
332 |
List<PathModel> allFiles = JGitUtils.getDocuments(repository, null);
|
|
333 |
repository.close();
|
|
334 |
assertTrue(markdownDocs.size() > 0);
|
|
335 |
assertTrue(markdownDocs2.size() > 0);
|
|
336 |
assertTrue(allFiles.size() > markdownDocs.size());
|
|
337 |
}
|
|
338 |
|
7e8873
|
339 |
@Test
|
a125cf
|
340 |
public void testFileModes() throws Exception {
|
7e8873
|
341 |
assertEquals("drwxr-xr-x", JGitUtils.getPermissionsFromMode(FileMode.TREE.getBits()));
|
JM |
342 |
assertEquals("-rw-r--r--",
|
|
343 |
JGitUtils.getPermissionsFromMode(FileMode.REGULAR_FILE.getBits()));
|
|
344 |
assertEquals("-rwxr-xr-x",
|
|
345 |
JGitUtils.getPermissionsFromMode(FileMode.EXECUTABLE_FILE.getBits()));
|
|
346 |
assertEquals("symlink", JGitUtils.getPermissionsFromMode(FileMode.SYMLINK.getBits()));
|
|
347 |
assertEquals("gitlink", JGitUtils.getPermissionsFromMode(FileMode.GITLINK.getBits()));
|
|
348 |
assertEquals("missing", JGitUtils.getPermissionsFromMode(FileMode.MISSING.getBits()));
|
a125cf
|
349 |
}
|
JM |
350 |
|
7e8873
|
351 |
@Test
|
a125cf
|
352 |
public void testRevlog() throws Exception {
|
85c2e6
|
353 |
assertTrue(JGitUtils.getRevLog(null, 0).size() == 0);
|
a125cf
|
354 |
List<RevCommit> commits = JGitUtils.getRevLog(null, 10);
|
2f1c77
|
355 |
assertEquals(0, commits.size());
|
a125cf
|
356 |
|
JM |
357 |
Repository repository = GitBlitSuite.getHelloworldRepository();
|
|
358 |
// get most recent 10 commits
|
|
359 |
commits = JGitUtils.getRevLog(repository, 10);
|
2f1c77
|
360 |
assertEquals(10, commits.size());
|
a125cf
|
361 |
|
JM |
362 |
// test paging and offset by getting the 10th most recent commit
|
|
363 |
RevCommit lastCommit = JGitUtils.getRevLog(repository, null, 9, 1).get(0);
|
2f1c77
|
364 |
assertEquals(lastCommit, commits.get(9));
|
a125cf
|
365 |
|
JM |
366 |
// grab the two most recent commits to java.java
|
|
367 |
commits = JGitUtils.getRevLog(repository, null, "java.java", 0, 2);
|
2f1c77
|
368 |
assertEquals(2, commits.size());
|
7e8873
|
369 |
|
2f1c77
|
370 |
// grab the commits since 2008-07-15
|
7e8873
|
371 |
commits = JGitUtils.getRevLog(repository, null,
|
JM |
372 |
new SimpleDateFormat("yyyy-MM-dd").parse("2008-07-15"));
|
2f1c77
|
373 |
assertEquals(12, commits.size());
|
a125cf
|
374 |
repository.close();
|
JM |
375 |
}
|
|
376 |
|
7e8873
|
377 |
@Test
|
f47590
|
378 |
public void testRevLogRange() throws Exception {
|
JM |
379 |
Repository repository = GitBlitSuite.getHelloworldRepository();
|
|
380 |
List<RevCommit> commits = JGitUtils.getRevLog(repository,
|
|
381 |
"fbd14fa6d1a01d4aefa1fca725792683800fc67e",
|
|
382 |
"85a0e4087b8439c0aa6b1f4f9e08c26052ab7e87");
|
|
383 |
repository.close();
|
|
384 |
assertEquals(14, commits.size());
|
|
385 |
}
|
|
386 |
|
|
387 |
@Test
|
a125cf
|
388 |
public void testSearchTypes() throws Exception {
|
7e8873
|
389 |
assertEquals(SearchType.COMMIT, SearchType.forName("commit"));
|
JM |
390 |
assertEquals(SearchType.COMMITTER, SearchType.forName("committer"));
|
|
391 |
assertEquals(SearchType.AUTHOR, SearchType.forName("author"));
|
|
392 |
assertEquals(SearchType.COMMIT, SearchType.forName("unknown"));
|
a125cf
|
393 |
|
7e8873
|
394 |
assertEquals("commit", SearchType.COMMIT.toString());
|
JM |
395 |
assertEquals("committer", SearchType.COMMITTER.toString());
|
|
396 |
assertEquals("author", SearchType.AUTHOR.toString());
|
a125cf
|
397 |
}
|
JM |
398 |
|
7e8873
|
399 |
@Test
|
a125cf
|
400 |
public void testSearchRevlogs() throws Exception {
|
7e8873
|
401 |
assertEquals(0, JGitUtils.searchRevlogs(null, null, "java", SearchType.COMMIT, 0, 0).size());
|
JM |
402 |
List<RevCommit> results = JGitUtils.searchRevlogs(null, null, "java", SearchType.COMMIT, 0,
|
a125cf
|
403 |
3);
|
7e8873
|
404 |
assertEquals(0, results.size());
|
a125cf
|
405 |
|
JM |
406 |
// test commit message search
|
|
407 |
Repository repository = GitBlitSuite.getHelloworldRepository();
|
7e8873
|
408 |
results = JGitUtils.searchRevlogs(repository, null, "java", SearchType.COMMIT, 0, 3);
|
JM |
409 |
assertEquals(3, results.size());
|
a125cf
|
410 |
|
JM |
411 |
// test author search
|
7e8873
|
412 |
results = JGitUtils.searchRevlogs(repository, null, "timothy", SearchType.AUTHOR, 0, -1);
|
JM |
413 |
assertEquals(1, results.size());
|
a125cf
|
414 |
|
JM |
415 |
// test committer search
|
7e8873
|
416 |
results = JGitUtils.searchRevlogs(repository, null, "mike", SearchType.COMMITTER, 0, 10);
|
JM |
417 |
assertEquals(10, results.size());
|
a125cf
|
418 |
|
JM |
419 |
// test paging and offset
|
7e8873
|
420 |
RevCommit commit = JGitUtils.searchRevlogs(repository, null, "mike", SearchType.COMMITTER,
|
a125cf
|
421 |
9, 1).get(0);
|
7e8873
|
422 |
assertEquals(results.get(9), commit);
|
a125cf
|
423 |
|
JM |
424 |
repository.close();
|
2a7306
|
425 |
}
|
JM |
426 |
|
7e8873
|
427 |
@Test
|
2a7306
|
428 |
public void testZip() throws Exception {
|
a125cf
|
429 |
assertFalse(JGitUtils.zip(null, null, null, null));
|
2a7306
|
430 |
Repository repository = GitBlitSuite.getHelloworldRepository();
|
a125cf
|
431 |
File zipFileA = new File(GitBlitSuite.REPOSITORIES, "helloworld.zip");
|
JM |
432 |
FileOutputStream fosA = new FileOutputStream(zipFileA);
|
|
433 |
boolean successA = JGitUtils.zip(repository, null, Constants.HEAD, fosA);
|
|
434 |
fosA.close();
|
|
435 |
|
|
436 |
File zipFileB = new File(GitBlitSuite.REPOSITORIES, "helloworld-java.zip");
|
|
437 |
FileOutputStream fosB = new FileOutputStream(zipFileB);
|
|
438 |
boolean successB = JGitUtils.zip(repository, "java.java", Constants.HEAD, fosB);
|
|
439 |
fosB.close();
|
|
440 |
|
2a7306
|
441 |
repository.close();
|
a125cf
|
442 |
assertTrue("Failed to generate zip file!", successA);
|
JM |
443 |
assertTrue(zipFileA.length() > 0);
|
|
444 |
zipFileA.delete();
|
|
445 |
|
|
446 |
assertTrue("Failed to generate zip file!", successB);
|
|
447 |
assertTrue(zipFileB.length() > 0);
|
|
448 |
zipFileB.delete();
|
2a7306
|
449 |
}
|
a2709d
|
450 |
|
2a7306
|
451 |
} |