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 |
|
|
18 |
import java.io.File;
|
|
19 |
import java.io.FileOutputStream;
|
2f1c77
|
20 |
import java.text.SimpleDateFormat;
|
a125cf
|
21 |
import java.util.Arrays;
|
2a7306
|
22 |
import java.util.Date;
|
JM |
23 |
import java.util.List;
|
a125cf
|
24 |
import java.util.Map;
|
2a7306
|
25 |
|
a125cf
|
26 |
import org.eclipse.jgit.diff.DiffEntry.ChangeType;
|
2a7306
|
27 |
import org.eclipse.jgit.lib.Constants;
|
a125cf
|
28 |
import org.eclipse.jgit.lib.FileMode;
|
JM |
29 |
import org.eclipse.jgit.lib.ObjectId;
|
|
30 |
import org.eclipse.jgit.lib.PersonIdent;
|
2a7306
|
31 |
import org.eclipse.jgit.lib.Repository;
|
20714a
|
32 |
import org.eclipse.jgit.lib.RepositoryCache;
|
168566
|
33 |
import org.eclipse.jgit.lib.RepositoryCache.FileKey;
|
f084f4
|
34 |
import org.eclipse.jgit.revplot.PlotCommit;
|
JM |
35 |
import org.eclipse.jgit.revplot.PlotCommitList;
|
|
36 |
import org.eclipse.jgit.revplot.PlotLane;
|
|
37 |
import org.eclipse.jgit.revplot.PlotWalk;
|
2a7306
|
38 |
import org.eclipse.jgit.revwalk.RevCommit;
|
ae9e15
|
39 |
import org.eclipse.jgit.revwalk.RevTree;
|
168566
|
40 |
import org.eclipse.jgit.util.FS;
|
a2709d
|
41 |
import org.eclipse.jgit.util.FileUtils;
|
7e8873
|
42 |
import org.junit.Test;
|
2a7306
|
43 |
|
7e8873
|
44 |
import com.gitblit.Constants.SearchType;
|
4ab184
|
45 |
import com.gitblit.models.GitNote;
|
a125cf
|
46 |
import com.gitblit.models.PathModel;
|
1f9dae
|
47 |
import com.gitblit.models.PathModel.PathChangeModel;
|
JM |
48 |
import com.gitblit.models.RefModel;
|
59b817
|
49 |
import com.gitblit.utils.CompressionUtils;
|
2a7306
|
50 |
import com.gitblit.utils.JGitUtils;
|
e85277
|
51 |
import com.gitblit.utils.JnaUtils;
|
4ab184
|
52 |
import com.gitblit.utils.StringUtils;
|
2a7306
|
53 |
|
db4f6b
|
54 |
public class JGitUtilsTest extends GitblitUnitTest {
|
a125cf
|
55 |
|
7e8873
|
56 |
@Test
|
a125cf
|
57 |
public void testDisplayName() throws Exception {
|
7e8873
|
58 |
assertEquals("Napoleon Bonaparte",
|
JM |
59 |
JGitUtils.getDisplayName(new PersonIdent("Napoleon Bonaparte", "")));
|
|
60 |
assertEquals("<someone@somewhere.com>",
|
|
61 |
JGitUtils.getDisplayName(new PersonIdent("", "someone@somewhere.com")));
|
|
62 |
assertEquals("Napoleon Bonaparte <someone@somewhere.com>",
|
|
63 |
JGitUtils.getDisplayName(new PersonIdent("Napoleon Bonaparte",
|
|
64 |
"someone@somewhere.com")));
|
a125cf
|
65 |
}
|
2a7306
|
66 |
|
7e8873
|
67 |
@Test
|
2a7306
|
68 |
public void testFindRepositories() {
|
0adceb
|
69 |
List<String> list = JGitUtils.getRepositoryList(null, false, true, -1, null);
|
7e8873
|
70 |
assertEquals(0, list.size());
|
0adceb
|
71 |
list.addAll(JGitUtils.getRepositoryList(new File("DoesNotExist"), true, true, -1, null));
|
7e8873
|
72 |
assertEquals(0, list.size());
|
0adceb
|
73 |
list.addAll(JGitUtils.getRepositoryList(GitBlitSuite.REPOSITORIES, false, true, -1, null));
|
2a7306
|
74 |
assertTrue("No repositories found in " + GitBlitSuite.REPOSITORIES, list.size() > 0);
|
JM |
75 |
}
|
|
76 |
|
7e8873
|
77 |
@Test
|
0adceb
|
78 |
public void testFindExclusions() {
|
JM |
79 |
List<String> list = JGitUtils.getRepositoryList(GitBlitSuite.REPOSITORIES, false, true, -1, null);
|
|
80 |
assertTrue("Missing jgit repository?!", list.contains("test/jgit.git"));
|
|
81 |
|
|
82 |
list = JGitUtils.getRepositoryList(GitBlitSuite.REPOSITORIES, false, true, -1, Arrays.asList("test/jgit\\.git"));
|
|
83 |
assertFalse("Repository exclusion failed!", list.contains("test/jgit.git"));
|
|
84 |
|
|
85 |
list = JGitUtils.getRepositoryList(GitBlitSuite.REPOSITORIES, false, true, -1, Arrays.asList("test/*"));
|
|
86 |
assertFalse("Repository exclusion failed!", list.contains("test/jgit.git"));
|
|
87 |
|
bb55f5
|
88 |
list = JGitUtils.getRepositoryList(GitBlitSuite.REPOSITORIES, false, true, -1, Arrays.asList(".*jgit.*"));
|
0adceb
|
89 |
assertFalse("Repository exclusion failed!", list.contains("test/jgit.git"));
|
JM |
90 |
assertFalse("Repository exclusion failed!", list.contains("working/jgit"));
|
|
91 |
assertFalse("Repository exclusion failed!", list.contains("working/jgit2"));
|
|
92 |
|
|
93 |
}
|
|
94 |
|
|
95 |
@Test
|
2a7306
|
96 |
public void testOpenRepository() throws Exception {
|
JM |
97 |
Repository repository = GitBlitSuite.getHelloworldRepository();
|
|
98 |
repository.close();
|
7e8873
|
99 |
assertNotNull("Could not find repository!", repository);
|
2a7306
|
100 |
}
|
JM |
101 |
|
7e8873
|
102 |
@Test
|
2a7306
|
103 |
public void testFirstCommit() throws Exception {
|
7e8873
|
104 |
assertEquals(new Date(0), JGitUtils.getFirstChange(null, null));
|
a125cf
|
105 |
|
2a7306
|
106 |
Repository repository = GitBlitSuite.getHelloworldRepository();
|
JM |
107 |
RevCommit commit = JGitUtils.getFirstCommit(repository, null);
|
db653a
|
108 |
Date firstChange = JGitUtils.getFirstChange(repository, null);
|
2a7306
|
109 |
repository.close();
|
7e8873
|
110 |
assertNotNull("Could not get first commit!", commit);
|
JM |
111 |
assertEquals("Incorrect first commit!", "f554664a346629dc2b839f7292d06bad2db4aece",
|
|
112 |
commit.getName());
|
db653a
|
113 |
assertTrue(firstChange.equals(new Date(commit.getCommitTime() * 1000L)));
|
f1720c
|
114 |
}
|
a125cf
|
115 |
|
7e8873
|
116 |
@Test
|
f1720c
|
117 |
public void testLastCommit() throws Exception {
|
5c5b7a
|
118 |
assertEquals(new Date(0), JGitUtils.getLastChange(null).when);
|
a125cf
|
119 |
|
f1720c
|
120 |
Repository repository = GitBlitSuite.getHelloworldRepository();
|
JM |
121 |
assertTrue(JGitUtils.getCommit(repository, null) != null);
|
5c5b7a
|
122 |
Date date = JGitUtils.getLastChange(repository).when;
|
f1720c
|
123 |
repository.close();
|
7e8873
|
124 |
assertNotNull("Could not get last repository change date!", date);
|
f1720c
|
125 |
}
|
JM |
126 |
|
7e8873
|
127 |
@Test
|
f1720c
|
128 |
public void testCreateRepository() throws Exception {
|
JM |
129 |
String[] repositories = { "NewTestRepository.git", "NewTestRepository" };
|
008322
|
130 |
for (String repositoryName : repositories) {
|
f1720c
|
131 |
Repository repository = JGitUtils.createRepository(GitBlitSuite.REPOSITORIES,
|
168566
|
132 |
repositoryName);
|
008322
|
133 |
File folder = FileKey.resolve(new File(GitBlitSuite.REPOSITORIES, repositoryName),
|
JM |
134 |
FS.DETECTED);
|
7e8873
|
135 |
assertNotNull(repository);
|
f1720c
|
136 |
assertFalse(JGitUtils.hasCommits(repository));
|
7e8873
|
137 |
assertNull(JGitUtils.getFirstCommit(repository, null));
|
JM |
138 |
assertEquals(folder.lastModified(), JGitUtils.getFirstChange(repository, null)
|
|
139 |
.getTime());
|
5c5b7a
|
140 |
assertEquals(folder.lastModified(), JGitUtils.getLastChange(repository).when.getTime());
|
7e8873
|
141 |
assertNull(JGitUtils.getCommit(repository, null));
|
f1720c
|
142 |
repository.close();
|
20714a
|
143 |
RepositoryCache.close(repository);
|
JM |
144 |
FileUtils.delete(repository.getDirectory(), FileUtils.RECURSIVE);
|
f1720c
|
145 |
}
|
2a7306
|
146 |
}
|
JM |
147 |
|
7e8873
|
148 |
@Test
|
8a67d9
|
149 |
public void testCreateRepositoryShared() throws Exception {
|
e85277
|
150 |
String[] repositories = { "NewSharedTestRepository.git" };
|
8a67d9
|
151 |
for (String repositoryName : repositories) {
|
FZ |
152 |
Repository repository = JGitUtils.createRepository(GitBlitSuite.REPOSITORIES,
|
|
153 |
repositoryName, "group");
|
|
154 |
File folder = FileKey.resolve(new File(GitBlitSuite.REPOSITORIES, repositoryName),
|
|
155 |
FS.DETECTED);
|
|
156 |
assertNotNull(repository);
|
|
157 |
assertFalse(JGitUtils.hasCommits(repository));
|
|
158 |
assertNull(JGitUtils.getFirstCommit(repository, null));
|
e85277
|
159 |
|
9d2f66
|
160 |
assertEquals("1", repository.getConfig().getString("core", null, "sharedRepository"));
|
FZ |
161 |
|
e85277
|
162 |
assertTrue(folder.exists());
|
9d2f66
|
163 |
if (! JnaUtils.isWindows()) {
|
FZ |
164 |
int mode = JnaUtils.getFilemode(folder);
|
|
165 |
assertEquals(JnaUtils.S_ISGID, mode & JnaUtils.S_ISGID);
|
|
166 |
assertEquals(JnaUtils.S_IRWXG, mode & JnaUtils.S_IRWXG);
|
e85277
|
167 |
|
9d2f66
|
168 |
mode = JnaUtils.getFilemode(folder.getAbsolutePath() + "/HEAD");
|
FZ |
169 |
assertEquals(JnaUtils.S_IRGRP | JnaUtils.S_IWGRP, mode & JnaUtils.S_IRWXG);
|
e85277
|
170 |
|
9d2f66
|
171 |
mode = JnaUtils.getFilemode(folder.getAbsolutePath() + "/config");
|
FZ |
172 |
assertEquals(JnaUtils.S_IRGRP | JnaUtils.S_IWGRP, mode & JnaUtils.S_IRWXG);
|
|
173 |
}
|
e85277
|
174 |
|
8a67d9
|
175 |
repository.close();
|
FZ |
176 |
RepositoryCache.close(repository);
|
e85277
|
177 |
FileUtils.delete(repository.getDirectory(), FileUtils.RECURSIVE);
|
8a67d9
|
178 |
}
|
FZ |
179 |
}
|
|
180 |
|
|
181 |
@Test
|
8b5730
|
182 |
public void testCreateRepositorySharedCustom() throws Exception {
|
FZ |
183 |
String[] repositories = { "NewSharedTestRepository.git" };
|
|
184 |
for (String repositoryName : repositories) {
|
|
185 |
Repository repository = JGitUtils.createRepository(GitBlitSuite.REPOSITORIES,
|
|
186 |
repositoryName, "660");
|
|
187 |
File folder = FileKey.resolve(new File(GitBlitSuite.REPOSITORIES, repositoryName),
|
|
188 |
FS.DETECTED);
|
|
189 |
assertNotNull(repository);
|
|
190 |
assertFalse(JGitUtils.hasCommits(repository));
|
|
191 |
assertNull(JGitUtils.getFirstCommit(repository, null));
|
|
192 |
|
|
193 |
assertEquals("0660", repository.getConfig().getString("core", null, "sharedRepository"));
|
|
194 |
|
|
195 |
assertTrue(folder.exists());
|
|
196 |
if (! JnaUtils.isWindows()) {
|
|
197 |
int mode = JnaUtils.getFilemode(folder);
|
|
198 |
assertEquals(JnaUtils.S_ISGID, mode & JnaUtils.S_ISGID);
|
|
199 |
assertEquals(JnaUtils.S_IRWXG, mode & JnaUtils.S_IRWXG);
|
|
200 |
assertEquals(0, mode & JnaUtils.S_IRWXO);
|
|
201 |
|
|
202 |
mode = JnaUtils.getFilemode(folder.getAbsolutePath() + "/HEAD");
|
|
203 |
assertEquals(JnaUtils.S_IRGRP | JnaUtils.S_IWGRP, mode & JnaUtils.S_IRWXG);
|
|
204 |
assertEquals(0, mode & JnaUtils.S_IRWXO);
|
|
205 |
|
|
206 |
mode = JnaUtils.getFilemode(folder.getAbsolutePath() + "/config");
|
|
207 |
assertEquals(JnaUtils.S_IRGRP | JnaUtils.S_IWGRP, mode & JnaUtils.S_IRWXG);
|
|
208 |
assertEquals(0, mode & JnaUtils.S_IRWXO);
|
|
209 |
}
|
|
210 |
|
|
211 |
repository.close();
|
|
212 |
RepositoryCache.close(repository);
|
|
213 |
FileUtils.delete(repository.getDirectory(), FileUtils.RECURSIVE);
|
|
214 |
}
|
|
215 |
}
|
|
216 |
|
|
217 |
@Test
|
b72444
|
218 |
public void testCreateRepositorySharedSgidParent() throws Exception {
|
FZ |
219 |
if (! JnaUtils.isWindows()) {
|
|
220 |
String repositoryAll = "NewTestRepositoryAll.git";
|
|
221 |
String repositoryUmask = "NewTestRepositoryUmask.git";
|
|
222 |
String sgidParent = "sgid";
|
c00577
|
223 |
|
b72444
|
224 |
File parent = new File(GitBlitSuite.REPOSITORIES, sgidParent);
|
FZ |
225 |
File folder = null;
|
|
226 |
boolean parentExisted = parent.exists();
|
|
227 |
try {
|
|
228 |
if (!parentExisted) {
|
|
229 |
assertTrue("Could not create SGID parent folder.", parent.mkdir());
|
|
230 |
}
|
|
231 |
int mode = JnaUtils.getFilemode(parent);
|
|
232 |
assertTrue(mode > 0);
|
|
233 |
assertEquals(0, JnaUtils.setFilemode(parent, mode | JnaUtils.S_ISGID | JnaUtils.S_IWGRP));
|
|
234 |
|
|
235 |
Repository repository = JGitUtils.createRepository(parent, repositoryAll, "all");
|
|
236 |
folder = FileKey.resolve(new File(parent, repositoryAll), FS.DETECTED);
|
|
237 |
assertNotNull(repository);
|
c00577
|
238 |
|
b72444
|
239 |
assertEquals("2", repository.getConfig().getString("core", null, "sharedRepository"));
|
c00577
|
240 |
|
b72444
|
241 |
assertTrue(folder.exists());
|
FZ |
242 |
mode = JnaUtils.getFilemode(folder);
|
|
243 |
assertEquals(JnaUtils.S_ISGID, mode & JnaUtils.S_ISGID);
|
c00577
|
244 |
|
b72444
|
245 |
mode = JnaUtils.getFilemode(folder.getAbsolutePath() + "/HEAD");
|
FZ |
246 |
assertEquals(JnaUtils.S_IRGRP | JnaUtils.S_IWGRP, mode & JnaUtils.S_IRWXG);
|
|
247 |
assertEquals(JnaUtils.S_IROTH, mode & JnaUtils.S_IRWXO);
|
c00577
|
248 |
|
b72444
|
249 |
mode = JnaUtils.getFilemode(folder.getAbsolutePath() + "/config");
|
FZ |
250 |
assertEquals(JnaUtils.S_IRGRP | JnaUtils.S_IWGRP, mode & JnaUtils.S_IRWXG);
|
|
251 |
assertEquals(JnaUtils.S_IROTH, mode & JnaUtils.S_IRWXO);
|
c00577
|
252 |
|
b72444
|
253 |
repository.close();
|
FZ |
254 |
RepositoryCache.close(repository);
|
|
255 |
|
|
256 |
|
|
257 |
|
|
258 |
repository = JGitUtils.createRepository(parent, repositoryUmask, "umask");
|
|
259 |
folder = FileKey.resolve(new File(parent, repositoryUmask), FS.DETECTED);
|
|
260 |
assertNotNull(repository);
|
c00577
|
261 |
|
b72444
|
262 |
assertEquals(null, repository.getConfig().getString("core", null, "sharedRepository"));
|
c00577
|
263 |
|
b72444
|
264 |
assertTrue(folder.exists());
|
FZ |
265 |
mode = JnaUtils.getFilemode(folder);
|
|
266 |
assertEquals(JnaUtils.S_ISGID, mode & JnaUtils.S_ISGID);
|
c00577
|
267 |
|
b72444
|
268 |
repository.close();
|
FZ |
269 |
RepositoryCache.close(repository);
|
|
270 |
}
|
|
271 |
finally {
|
|
272 |
FileUtils.delete(new File(parent, repositoryAll), FileUtils.RECURSIVE | FileUtils.IGNORE_ERRORS);
|
|
273 |
FileUtils.delete(new File(parent, repositoryUmask), FileUtils.RECURSIVE | FileUtils.IGNORE_ERRORS);
|
|
274 |
if (!parentExisted) {
|
|
275 |
FileUtils.delete(parent, FileUtils.RECURSIVE | FileUtils.IGNORE_ERRORS);
|
|
276 |
}
|
|
277 |
}
|
|
278 |
}
|
|
279 |
}
|
|
280 |
|
|
281 |
@Test
|
28d6b2
|
282 |
public void testRefs() throws Exception {
|
4ab184
|
283 |
Repository repository = GitBlitSuite.getJGitRepository();
|
JM |
284 |
Map<ObjectId, List<RefModel>> map = JGitUtils.getAllRefs(repository);
|
a125cf
|
285 |
repository.close();
|
JM |
286 |
assertTrue(map.size() > 0);
|
4ab184
|
287 |
for (Map.Entry<ObjectId, List<RefModel>> entry : map.entrySet()) {
|
JM |
288 |
List<RefModel> list = entry.getValue();
|
|
289 |
for (RefModel ref : list) {
|
|
290 |
if (ref.displayName.equals("refs/tags/spearce-gpg-pub")) {
|
7e8873
|
291 |
assertEquals("refs/tags/spearce-gpg-pub", ref.toString());
|
JM |
292 |
assertEquals("8bbde7aacf771a9afb6992434f1ae413e010c6d8", ref.getObjectId()
|
|
293 |
.getName());
|
|
294 |
assertEquals("spearce@spearce.org", ref.getAuthorIdent().getEmailAddress());
|
4ab184
|
295 |
assertTrue(ref.getShortMessage().startsWith("GPG key"));
|
008322
|
296 |
assertTrue(ref.getFullMessage().startsWith("GPG key"));
|
7e8873
|
297 |
assertEquals(Constants.OBJ_BLOB, ref.getReferencedObjectType());
|
4ab184
|
298 |
} else if (ref.displayName.equals("refs/tags/v0.12.1")) {
|
JM |
299 |
assertTrue(ref.isAnnotatedTag());
|
|
300 |
}
|
|
301 |
}
|
|
302 |
}
|
a125cf
|
303 |
}
|
JM |
304 |
|
7e8873
|
305 |
@Test
|
a125cf
|
306 |
public void testBranches() throws Exception {
|
168566
|
307 |
Repository repository = GitBlitSuite.getJGitRepository();
|
85c2e6
|
308 |
assertTrue(JGitUtils.getLocalBranches(repository, true, 0).size() == 0);
|
5cc4f2
|
309 |
for (RefModel model : JGitUtils.getLocalBranches(repository, true, -1)) {
|
28d6b2
|
310 |
assertTrue(model.getName().startsWith(Constants.R_HEADS));
|
JM |
311 |
assertTrue(model.equals(model));
|
|
312 |
assertFalse(model.equals(""));
|
4ab184
|
313 |
assertTrue(model.hashCode() == model.getReferencedObjectId().hashCode()
|
28d6b2
|
314 |
+ model.getName().hashCode());
|
4ab184
|
315 |
assertTrue(model.getShortMessage().equals(model.getShortMessage()));
|
28d6b2
|
316 |
}
|
5cc4f2
|
317 |
for (RefModel model : JGitUtils.getRemoteBranches(repository, true, -1)) {
|
28d6b2
|
318 |
assertTrue(model.getName().startsWith(Constants.R_REMOTES));
|
JM |
319 |
assertTrue(model.equals(model));
|
|
320 |
assertFalse(model.equals(""));
|
4ab184
|
321 |
assertTrue(model.hashCode() == model.getReferencedObjectId().hashCode()
|
28d6b2
|
322 |
+ model.getName().hashCode());
|
4ab184
|
323 |
assertTrue(model.getShortMessage().equals(model.getShortMessage()));
|
28d6b2
|
324 |
}
|
168566
|
325 |
assertTrue(JGitUtils.getRemoteBranches(repository, true, 8).size() == 8);
|
a125cf
|
326 |
repository.close();
|
JM |
327 |
}
|
|
328 |
|
7e8873
|
329 |
@Test
|
a125cf
|
330 |
public void testTags() throws Exception {
|
168566
|
331 |
Repository repository = GitBlitSuite.getJGitRepository();
|
85c2e6
|
332 |
assertTrue(JGitUtils.getTags(repository, true, 5).size() == 5);
|
5cc4f2
|
333 |
for (RefModel model : JGitUtils.getTags(repository, true, -1)) {
|
168566
|
334 |
if (model.getObjectId().getName().equals("d28091fb2977077471138fe97da1440e0e8ae0da")) {
|
28d6b2
|
335 |
assertTrue("Not an annotated tag!", model.isAnnotatedTag());
|
JM |
336 |
}
|
|
337 |
assertTrue(model.getName().startsWith(Constants.R_TAGS));
|
|
338 |
assertTrue(model.equals(model));
|
|
339 |
assertFalse(model.equals(""));
|
4ab184
|
340 |
assertTrue(model.hashCode() == model.getReferencedObjectId().hashCode()
|
28d6b2
|
341 |
+ model.getName().hashCode());
|
4ab184
|
342 |
}
|
JM |
343 |
repository.close();
|
008322
|
344 |
|
d3065f
|
345 |
repository = GitBlitSuite.getGitectiveRepository();
|
5cc4f2
|
346 |
for (RefModel model : JGitUtils.getTags(repository, true, -1)) {
|
d3065f
|
347 |
if (model.getObjectId().getName().equals("035254295a9bba11f72b1f9d6791a6b957abee7b")) {
|
4ab184
|
348 |
assertFalse(model.isAnnotatedTag());
|
d3065f
|
349 |
assertTrue(model.getAuthorIdent().getEmailAddress().equals("kevinsawicki@gmail.com"));
|
JM |
350 |
assertEquals("Add scm and issue tracker elements to pom.xml\n", model.getFullMessage());
|
4ab184
|
351 |
}
|
28d6b2
|
352 |
}
|
JM |
353 |
repository.close();
|
|
354 |
}
|
|
355 |
|
7e8873
|
356 |
@Test
|
a125cf
|
357 |
public void testCommitNotes() throws Exception {
|
4ab184
|
358 |
Repository repository = GitBlitSuite.getJGitRepository();
|
JM |
359 |
RevCommit commit = JGitUtils.getCommit(repository,
|
|
360 |
"690c268c793bfc218982130fbfc25870f292295e");
|
|
361 |
List<GitNote> list = JGitUtils.getNotesOnCommit(repository, commit);
|
|
362 |
repository.close();
|
|
363 |
assertTrue(list.size() > 0);
|
7e8873
|
364 |
assertEquals("183474d554e6f68478a02d9d7888b67a9338cdff", list.get(0).notesRef
|
JM |
365 |
.getReferencedObjectId().getName());
|
2a7306
|
366 |
}
|
c00577
|
367 |
|
90b8d7
|
368 |
@Test
|
JM |
369 |
public void testRelinkHEAD() throws Exception {
|
|
370 |
Repository repository = GitBlitSuite.getJGitRepository();
|
|
371 |
// confirm HEAD is master
|
|
372 |
String currentRef = JGitUtils.getHEADRef(repository);
|
|
373 |
assertEquals("refs/heads/master", currentRef);
|
|
374 |
List<String> availableHeads = JGitUtils.getAvailableHeadTargets(repository);
|
|
375 |
assertTrue(availableHeads.size() > 0);
|
c00577
|
376 |
|
90b8d7
|
377 |
// set HEAD to stable-1.2
|
JM |
378 |
JGitUtils.setHEADtoRef(repository, "refs/heads/stable-1.2");
|
|
379 |
currentRef = JGitUtils.getHEADRef(repository);
|
|
380 |
assertEquals("refs/heads/stable-1.2", currentRef);
|
|
381 |
|
|
382 |
// restore HEAD to master
|
|
383 |
JGitUtils.setHEADtoRef(repository, "refs/heads/master");
|
|
384 |
currentRef = JGitUtils.getHEADRef(repository);
|
|
385 |
assertEquals("refs/heads/master", currentRef);
|
c00577
|
386 |
|
90b8d7
|
387 |
repository.close();
|
JM |
388 |
}
|
2a7306
|
389 |
|
7e8873
|
390 |
@Test
|
f96d32
|
391 |
public void testRelinkBranch() throws Exception {
|
JM |
392 |
Repository repository = GitBlitSuite.getJGitRepository();
|
c00577
|
393 |
|
f96d32
|
394 |
// create/set the branch
|
JM |
395 |
JGitUtils.setBranchRef(repository, "refs/heads/reftest", "3b358ce514ec655d3ff67de1430994d8428cdb04");
|
|
396 |
assertEquals(1, JGitUtils.getAllRefs(repository).get(ObjectId.fromString("3b358ce514ec655d3ff67de1430994d8428cdb04")).size());
|
|
397 |
assertEquals(null, JGitUtils.getAllRefs(repository).get(ObjectId.fromString("755dfdb40948f5c1ec79e06bde3b0a78c352f27f")));
|
c00577
|
398 |
|
f96d32
|
399 |
// reset the branch
|
JM |
400 |
JGitUtils.setBranchRef(repository, "refs/heads/reftest", "755dfdb40948f5c1ec79e06bde3b0a78c352f27f");
|
|
401 |
assertEquals(null, JGitUtils.getAllRefs(repository).get(ObjectId.fromString("3b358ce514ec655d3ff67de1430994d8428cdb04")));
|
|
402 |
assertEquals(1, JGitUtils.getAllRefs(repository).get(ObjectId.fromString("755dfdb40948f5c1ec79e06bde3b0a78c352f27f")).size());
|
|
403 |
|
|
404 |
// delete the branch
|
|
405 |
assertTrue(JGitUtils.deleteBranchRef(repository, "refs/heads/reftest"));
|
|
406 |
repository.close();
|
|
407 |
}
|
|
408 |
|
|
409 |
@Test
|
a2709d
|
410 |
public void testCreateOrphanedBranch() throws Exception {
|
671c19
|
411 |
Repository repository = JGitUtils.createRepository(GitBlitSuite.REPOSITORIES, "orphantest");
|
a2709d
|
412 |
assertTrue(JGitUtils.createOrphanBranch(repository,
|
7b0895
|
413 |
"x" + Long.toHexString(System.currentTimeMillis()).toUpperCase(), null));
|
JM |
414 |
FileUtils.delete(repository.getDirectory(), FileUtils.RECURSIVE);
|
a2709d
|
415 |
}
|
JM |
416 |
|
7e8873
|
417 |
@Test
|
a125cf
|
418 |
public void testStringContent() throws Exception {
|
2a7306
|
419 |
Repository repository = GitBlitSuite.getHelloworldRepository();
|
ae9e15
|
420 |
String contentA = JGitUtils.getStringContent(repository, (RevTree) null, "java.java");
|
2a7306
|
421 |
RevCommit commit = JGitUtils.getCommit(repository, Constants.HEAD);
|
4ab184
|
422 |
String contentB = JGitUtils.getStringContent(repository, commit.getTree(), "java.java");
|
74344a
|
423 |
|
JM |
424 |
assertTrue("ContentA is null!", contentA != null && contentA.length() > 0);
|
|
425 |
assertTrue("ContentB is null!", contentB != null && contentB.length() > 0);
|
|
426 |
assertTrue(contentA.equals(contentB));
|
|
427 |
|
4ab184
|
428 |
String contentC = JGitUtils.getStringContent(repository, commit.getTree(), "missing.txt");
|
JM |
429 |
|
|
430 |
// manually construct a blob, calculate the hash, lookup the hash in git
|
|
431 |
StringBuilder sb = new StringBuilder();
|
|
432 |
sb.append("blob ").append(contentA.length()).append('\0');
|
|
433 |
sb.append(contentA);
|
|
434 |
String sha1 = StringUtils.getSHA1(sb.toString());
|
|
435 |
String contentD = JGitUtils.getStringContent(repository, sha1);
|
2a7306
|
436 |
repository.close();
|
7e8873
|
437 |
assertNull(contentC);
|
4ab184
|
438 |
assertTrue(contentA.equals(contentD));
|
2a7306
|
439 |
}
|
JM |
440 |
|
7e8873
|
441 |
@Test
|
2a7306
|
442 |
public void testFilesInCommit() throws Exception {
|
JM |
443 |
Repository repository = GitBlitSuite.getHelloworldRepository();
|
|
444 |
RevCommit commit = JGitUtils.getCommit(repository,
|
|
445 |
"1d0c2933a4ae69c362f76797d42d6bd182d05176");
|
|
446 |
List<PathChangeModel> paths = JGitUtils.getFilesInCommit(repository, commit);
|
a125cf
|
447 |
|
JM |
448 |
commit = JGitUtils.getCommit(repository, "af0e9b2891fda85afc119f04a69acf7348922830");
|
|
449 |
List<PathChangeModel> deletions = JGitUtils.getFilesInCommit(repository, commit);
|
|
450 |
|
|
451 |
commit = JGitUtils.getFirstCommit(repository, null);
|
|
452 |
List<PathChangeModel> additions = JGitUtils.getFilesInCommit(repository, commit);
|
|
453 |
|
|
454 |
List<PathChangeModel> latestChanges = JGitUtils.getFilesInCommit(repository, null);
|
|
455 |
|
2a7306
|
456 |
repository.close();
|
JM |
457 |
assertTrue("No changed paths found!", paths.size() == 1);
|
28d6b2
|
458 |
for (PathChangeModel path : paths) {
|
JM |
459 |
assertTrue("PathChangeModel hashcode incorrect!",
|
|
460 |
path.hashCode() == (path.commitId.hashCode() + path.path.hashCode()));
|
|
461 |
assertTrue("PathChangeModel equals itself failed!", path.equals(path));
|
|
462 |
assertFalse("PathChangeModel equals string failed!", path.equals(""));
|
|
463 |
}
|
7e8873
|
464 |
assertEquals(ChangeType.DELETE, deletions.get(0).changeType);
|
JM |
465 |
assertEquals(ChangeType.ADD, additions.get(0).changeType);
|
a125cf
|
466 |
assertTrue(latestChanges.size() > 0);
|
JM |
467 |
}
|
|
468 |
|
7e8873
|
469 |
@Test
|
a125cf
|
470 |
public void testFilesInPath() throws Exception {
|
7e8873
|
471 |
assertEquals(0, JGitUtils.getFilesInPath(null, null, null).size());
|
a125cf
|
472 |
Repository repository = GitBlitSuite.getHelloworldRepository();
|
JM |
473 |
List<PathModel> files = JGitUtils.getFilesInPath(repository, null, null);
|
|
474 |
repository.close();
|
|
475 |
assertTrue(files.size() > 10);
|
|
476 |
}
|
|
477 |
|
7e8873
|
478 |
@Test
|
a125cf
|
479 |
public void testDocuments() throws Exception {
|
JM |
480 |
Repository repository = GitBlitSuite.getTicgitRepository();
|
1feb04
|
481 |
List<String> extensions = Arrays.asList(new String[] { ".mkd", ".md" });
|
a125cf
|
482 |
List<PathModel> markdownDocs = JGitUtils.getDocuments(repository, extensions);
|
JM |
483 |
List<PathModel> allFiles = JGitUtils.getDocuments(repository, null);
|
|
484 |
repository.close();
|
|
485 |
assertTrue(markdownDocs.size() > 0);
|
|
486 |
assertTrue(allFiles.size() > markdownDocs.size());
|
|
487 |
}
|
|
488 |
|
7e8873
|
489 |
@Test
|
a125cf
|
490 |
public void testFileModes() throws Exception {
|
7e8873
|
491 |
assertEquals("drwxr-xr-x", JGitUtils.getPermissionsFromMode(FileMode.TREE.getBits()));
|
JM |
492 |
assertEquals("-rw-r--r--",
|
|
493 |
JGitUtils.getPermissionsFromMode(FileMode.REGULAR_FILE.getBits()));
|
|
494 |
assertEquals("-rwxr-xr-x",
|
|
495 |
JGitUtils.getPermissionsFromMode(FileMode.EXECUTABLE_FILE.getBits()));
|
|
496 |
assertEquals("symlink", JGitUtils.getPermissionsFromMode(FileMode.SYMLINK.getBits()));
|
45f5f2
|
497 |
assertEquals("submodule", JGitUtils.getPermissionsFromMode(FileMode.GITLINK.getBits()));
|
7e8873
|
498 |
assertEquals("missing", JGitUtils.getPermissionsFromMode(FileMode.MISSING.getBits()));
|
a125cf
|
499 |
}
|
JM |
500 |
|
7e8873
|
501 |
@Test
|
a125cf
|
502 |
public void testRevlog() throws Exception {
|
85c2e6
|
503 |
assertTrue(JGitUtils.getRevLog(null, 0).size() == 0);
|
a125cf
|
504 |
List<RevCommit> commits = JGitUtils.getRevLog(null, 10);
|
2f1c77
|
505 |
assertEquals(0, commits.size());
|
a125cf
|
506 |
|
JM |
507 |
Repository repository = GitBlitSuite.getHelloworldRepository();
|
|
508 |
// get most recent 10 commits
|
|
509 |
commits = JGitUtils.getRevLog(repository, 10);
|
2f1c77
|
510 |
assertEquals(10, commits.size());
|
a125cf
|
511 |
|
JM |
512 |
// test paging and offset by getting the 10th most recent commit
|
|
513 |
RevCommit lastCommit = JGitUtils.getRevLog(repository, null, 9, 1).get(0);
|
2f1c77
|
514 |
assertEquals(lastCommit, commits.get(9));
|
a125cf
|
515 |
|
JM |
516 |
// grab the two most recent commits to java.java
|
|
517 |
commits = JGitUtils.getRevLog(repository, null, "java.java", 0, 2);
|
2f1c77
|
518 |
assertEquals(2, commits.size());
|
7e8873
|
519 |
|
2f1c77
|
520 |
// grab the commits since 2008-07-15
|
7e8873
|
521 |
commits = JGitUtils.getRevLog(repository, null,
|
JM |
522 |
new SimpleDateFormat("yyyy-MM-dd").parse("2008-07-15"));
|
5da0fd
|
523 |
assertEquals(12, commits.size());
|
a125cf
|
524 |
repository.close();
|
JM |
525 |
}
|
|
526 |
|
7e8873
|
527 |
@Test
|
f47590
|
528 |
public void testRevLogRange() throws Exception {
|
JM |
529 |
Repository repository = GitBlitSuite.getHelloworldRepository();
|
|
530 |
List<RevCommit> commits = JGitUtils.getRevLog(repository,
|
|
531 |
"fbd14fa6d1a01d4aefa1fca725792683800fc67e",
|
|
532 |
"85a0e4087b8439c0aa6b1f4f9e08c26052ab7e87");
|
|
533 |
repository.close();
|
|
534 |
assertEquals(14, commits.size());
|
|
535 |
}
|
|
536 |
|
|
537 |
@Test
|
a125cf
|
538 |
public void testSearchTypes() throws Exception {
|
7e8873
|
539 |
assertEquals(SearchType.COMMIT, SearchType.forName("commit"));
|
JM |
540 |
assertEquals(SearchType.COMMITTER, SearchType.forName("committer"));
|
|
541 |
assertEquals(SearchType.AUTHOR, SearchType.forName("author"));
|
|
542 |
assertEquals(SearchType.COMMIT, SearchType.forName("unknown"));
|
a125cf
|
543 |
|
7e8873
|
544 |
assertEquals("commit", SearchType.COMMIT.toString());
|
JM |
545 |
assertEquals("committer", SearchType.COMMITTER.toString());
|
|
546 |
assertEquals("author", SearchType.AUTHOR.toString());
|
a125cf
|
547 |
}
|
JM |
548 |
|
7e8873
|
549 |
@Test
|
a125cf
|
550 |
public void testSearchRevlogs() throws Exception {
|
7e8873
|
551 |
assertEquals(0, JGitUtils.searchRevlogs(null, null, "java", SearchType.COMMIT, 0, 0).size());
|
JM |
552 |
List<RevCommit> results = JGitUtils.searchRevlogs(null, null, "java", SearchType.COMMIT, 0,
|
a125cf
|
553 |
3);
|
7e8873
|
554 |
assertEquals(0, results.size());
|
a125cf
|
555 |
|
JM |
556 |
// test commit message search
|
|
557 |
Repository repository = GitBlitSuite.getHelloworldRepository();
|
7e8873
|
558 |
results = JGitUtils.searchRevlogs(repository, null, "java", SearchType.COMMIT, 0, 3);
|
JM |
559 |
assertEquals(3, results.size());
|
a125cf
|
560 |
|
JM |
561 |
// test author search
|
7e8873
|
562 |
results = JGitUtils.searchRevlogs(repository, null, "timothy", SearchType.AUTHOR, 0, -1);
|
JM |
563 |
assertEquals(1, results.size());
|
a125cf
|
564 |
|
JM |
565 |
// test committer search
|
7e8873
|
566 |
results = JGitUtils.searchRevlogs(repository, null, "mike", SearchType.COMMITTER, 0, 10);
|
JM |
567 |
assertEquals(10, results.size());
|
a125cf
|
568 |
|
JM |
569 |
// test paging and offset
|
7e8873
|
570 |
RevCommit commit = JGitUtils.searchRevlogs(repository, null, "mike", SearchType.COMMITTER,
|
a125cf
|
571 |
9, 1).get(0);
|
7e8873
|
572 |
assertEquals(results.get(9), commit);
|
a125cf
|
573 |
|
JM |
574 |
repository.close();
|
2a7306
|
575 |
}
|
JM |
576 |
|
7e8873
|
577 |
@Test
|
2a7306
|
578 |
public void testZip() throws Exception {
|
59b817
|
579 |
assertFalse(CompressionUtils.zip(null, null, null, null));
|
2a7306
|
580 |
Repository repository = GitBlitSuite.getHelloworldRepository();
|
a125cf
|
581 |
File zipFileA = new File(GitBlitSuite.REPOSITORIES, "helloworld.zip");
|
JM |
582 |
FileOutputStream fosA = new FileOutputStream(zipFileA);
|
59b817
|
583 |
boolean successA = CompressionUtils.zip(repository, null, Constants.HEAD, fosA);
|
a125cf
|
584 |
fosA.close();
|
JM |
585 |
|
|
586 |
File zipFileB = new File(GitBlitSuite.REPOSITORIES, "helloworld-java.zip");
|
|
587 |
FileOutputStream fosB = new FileOutputStream(zipFileB);
|
59b817
|
588 |
boolean successB = CompressionUtils.zip(repository, "java.java", Constants.HEAD, fosB);
|
a125cf
|
589 |
fosB.close();
|
JM |
590 |
|
2a7306
|
591 |
repository.close();
|
a125cf
|
592 |
assertTrue("Failed to generate zip file!", successA);
|
JM |
593 |
assertTrue(zipFileA.length() > 0);
|
|
594 |
zipFileA.delete();
|
|
595 |
|
|
596 |
assertTrue("Failed to generate zip file!", successB);
|
|
597 |
assertTrue(zipFileB.length() > 0);
|
|
598 |
zipFileB.delete();
|
2a7306
|
599 |
}
|
c00577
|
600 |
|
f084f4
|
601 |
@Test
|
JM |
602 |
public void testPlots() throws Exception {
|
|
603 |
Repository repository = GitBlitSuite.getTicgitRepository();
|
|
604 |
PlotWalk pw = new PlotWalk(repository);
|
|
605 |
PlotCommitList<PlotLane> commits = new PlotCommitList<PlotLane>();
|
|
606 |
commits.source(pw);
|
|
607 |
commits.fillTo(25);
|
|
608 |
for (PlotCommit<PlotLane> commit : commits) {
|
|
609 |
System.out.println(commit);
|
|
610 |
}
|
|
611 |
repository.close();
|
|
612 |
}
|
2a7306
|
613 |
} |