commit | author | age
|
db653a
|
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.assertTrue;
|
f339f5
|
20 |
|
7e8873
|
21 |
import java.util.List;
|
db653a
|
22 |
|
JM |
23 |
import org.eclipse.jgit.lib.Repository;
|
|
24 |
import org.eclipse.jgit.revwalk.RevCommit;
|
7e8873
|
25 |
import org.junit.Test;
|
db653a
|
26 |
|
f339f5
|
27 |
import com.gitblit.models.AnnotatedLine;
|
db653a
|
28 |
import com.gitblit.utils.DiffUtils;
|
a125cf
|
29 |
import com.gitblit.utils.DiffUtils.DiffOutputType;
|
db653a
|
30 |
import com.gitblit.utils.JGitUtils;
|
JM |
31 |
|
7e8873
|
32 |
public class DiffUtilsTest {
|
db653a
|
33 |
|
7e8873
|
34 |
@Test
|
f339f5
|
35 |
public void testDiffOutputTypes() throws Exception {
|
7e8873
|
36 |
assertEquals(DiffOutputType.PLAIN, DiffOutputType.forName("plain"));
|
JM |
37 |
assertEquals(DiffOutputType.GITWEB, DiffOutputType.forName("gitweb"));
|
|
38 |
assertEquals(DiffOutputType.GITBLIT, DiffOutputType.forName("gitblit"));
|
|
39 |
assertEquals(null, DiffOutputType.forName(null));
|
f339f5
|
40 |
}
|
85c2e6
|
41 |
|
7e8873
|
42 |
@Test
|
db653a
|
43 |
public void testParentCommitDiff() throws Exception {
|
JM |
44 |
Repository repository = GitBlitSuite.getHelloworldRepository();
|
|
45 |
RevCommit commit = JGitUtils.getCommit(repository,
|
|
46 |
"1d0c2933a4ae69c362f76797d42d6bd182d05176");
|
|
47 |
String diff = DiffUtils.getCommitDiff(repository, commit, DiffOutputType.PLAIN);
|
|
48 |
repository.close();
|
|
49 |
assertTrue(diff != null && diff.length() > 0);
|
|
50 |
String expected = "- system.out.println(\"Hello World\");\n+ System.out.println(\"Hello World\"";
|
|
51 |
assertTrue(diff.indexOf(expected) > -1);
|
|
52 |
}
|
|
53 |
|
7e8873
|
54 |
@Test
|
db653a
|
55 |
public void testArbitraryCommitDiff() throws Exception {
|
JM |
56 |
Repository repository = GitBlitSuite.getHelloworldRepository();
|
|
57 |
RevCommit baseCommit = JGitUtils.getCommit(repository,
|
|
58 |
"8baf6a833b5579384d9b9ceb8a16b5d0ea2ec4ca");
|
|
59 |
RevCommit commit = JGitUtils.getCommit(repository,
|
|
60 |
"1d0c2933a4ae69c362f76797d42d6bd182d05176");
|
|
61 |
String diff = DiffUtils.getDiff(repository, baseCommit, commit, DiffOutputType.PLAIN);
|
|
62 |
repository.close();
|
|
63 |
assertTrue(diff != null && diff.length() > 0);
|
|
64 |
String expected = "- system.out.println(\"Hello World\");\n+ System.out.println(\"Hello World\"";
|
|
65 |
assertTrue(diff.indexOf(expected) > -1);
|
|
66 |
}
|
|
67 |
|
7e8873
|
68 |
@Test
|
db653a
|
69 |
public void testPlainFileDiff() throws Exception {
|
JM |
70 |
Repository repository = GitBlitSuite.getHelloworldRepository();
|
|
71 |
RevCommit commit = JGitUtils.getCommit(repository,
|
|
72 |
"1d0c2933a4ae69c362f76797d42d6bd182d05176");
|
|
73 |
String diff = DiffUtils.getDiff(repository, commit, "java.java", DiffOutputType.PLAIN);
|
|
74 |
repository.close();
|
|
75 |
assertTrue(diff != null && diff.length() > 0);
|
|
76 |
String expected = "- system.out.println(\"Hello World\");\n+ System.out.println(\"Hello World\"";
|
|
77 |
assertTrue(diff.indexOf(expected) > -1);
|
|
78 |
}
|
|
79 |
|
7e8873
|
80 |
@Test
|
db653a
|
81 |
public void testFilePatch() throws Exception {
|
JM |
82 |
Repository repository = GitBlitSuite.getHelloworldRepository();
|
|
83 |
RevCommit commit = JGitUtils.getCommit(repository,
|
|
84 |
"1d0c2933a4ae69c362f76797d42d6bd182d05176");
|
|
85 |
String patch = DiffUtils.getCommitPatch(repository, null, commit, "java.java");
|
|
86 |
repository.close();
|
|
87 |
assertTrue(patch != null && patch.length() > 0);
|
|
88 |
String expected = "- system.out.println(\"Hello World\");\n+ System.out.println(\"Hello World\"";
|
|
89 |
assertTrue(patch.indexOf(expected) > -1);
|
|
90 |
}
|
|
91 |
|
7e8873
|
92 |
@Test
|
db653a
|
93 |
public void testArbitraryFilePatch() throws Exception {
|
JM |
94 |
Repository repository = GitBlitSuite.getHelloworldRepository();
|
|
95 |
RevCommit baseCommit = JGitUtils.getCommit(repository,
|
|
96 |
"8baf6a833b5579384d9b9ceb8a16b5d0ea2ec4ca");
|
|
97 |
RevCommit commit = JGitUtils.getCommit(repository,
|
|
98 |
"1d0c2933a4ae69c362f76797d42d6bd182d05176");
|
|
99 |
String patch = DiffUtils.getCommitPatch(repository, baseCommit, commit, "java.java");
|
|
100 |
repository.close();
|
|
101 |
assertTrue(patch != null && patch.length() > 0);
|
|
102 |
String expected = "- system.out.println(\"Hello World\");\n+ System.out.println(\"Hello World\"";
|
|
103 |
assertTrue(patch.indexOf(expected) > -1);
|
|
104 |
}
|
|
105 |
|
7e8873
|
106 |
@Test
|
db653a
|
107 |
public void testArbitraryCommitPatch() throws Exception {
|
JM |
108 |
Repository repository = GitBlitSuite.getHelloworldRepository();
|
|
109 |
RevCommit baseCommit = JGitUtils.getCommit(repository,
|
|
110 |
"8baf6a833b5579384d9b9ceb8a16b5d0ea2ec4ca");
|
|
111 |
RevCommit commit = JGitUtils.getCommit(repository,
|
|
112 |
"1d0c2933a4ae69c362f76797d42d6bd182d05176");
|
|
113 |
String patch = DiffUtils.getCommitPatch(repository, baseCommit, commit, null);
|
|
114 |
repository.close();
|
|
115 |
assertTrue(patch != null && patch.length() > 0);
|
|
116 |
String expected = "- system.out.println(\"Hello World\");\n+ System.out.println(\"Hello World\"";
|
|
117 |
assertTrue(patch.indexOf(expected) > -1);
|
|
118 |
}
|
85c2e6
|
119 |
|
7e8873
|
120 |
@Test
|
f339f5
|
121 |
public void testBlame() throws Exception {
|
JM |
122 |
Repository repository = GitBlitSuite.getHelloworldRepository();
|
85c2e6
|
123 |
List<AnnotatedLine> lines = DiffUtils.blame(repository, "java.java",
|
JM |
124 |
"1d0c2933a4ae69c362f76797d42d6bd182d05176");
|
f339f5
|
125 |
repository.close();
|
JM |
126 |
assertTrue(lines.size() > 0);
|
7e8873
|
127 |
assertEquals("c6d31dccf5cc75e8e46299fc62d38f60ec6d41e0", lines.get(0).commitId);
|
f339f5
|
128 |
}
|
db653a
|
129 |
}
|