1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.git; |
21 |
|
|
22 |
|
import java.io.File; |
23 |
|
import java.io.PrintWriter; |
24 |
|
|
25 |
|
import org.eclipse.jgit.api.Git; |
26 |
|
import org.eclipse.jgit.lib.PersonIdent; |
27 |
|
import org.eclipse.jgit.lib.Repository; |
28 |
|
import org.eclipse.jgit.revwalk.RevCommit; |
29 |
|
import org.eclipse.jgit.storage.file.FileRepositoryBuilder; |
30 |
|
import org.junit.*; |
31 |
|
import org.xwiki.environment.Environment; |
32 |
|
|
|
|
| 80% |
Uncovered Elements: 8 (40) |
Complexity: 9 |
Complexity Density: 0.33 |
|
33 |
|
public class GitHelper |
34 |
|
{ |
35 |
|
private Environment environment; |
36 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
37 |
2 |
public GitHelper(Environment environment)... |
38 |
|
{ |
39 |
2 |
this.environment = environment; |
40 |
|
} |
41 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
42 |
6 |
public File getRepositoryFile(String repoName) throws Exception... |
43 |
|
{ |
44 |
6 |
File localGitDirectory = new File(this.environment.getPermanentDirectory(), "git"); |
45 |
6 |
File localDirectory = new File(localGitDirectory, repoName); |
46 |
6 |
return localDirectory; |
47 |
|
} |
48 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
49 |
0 |
public boolean exists(String repoName) throws Exception... |
50 |
|
{ |
51 |
0 |
return getRepositoryFile(repoName).exists(); |
52 |
|
} |
53 |
|
|
|
|
| 88.9% |
Uncovered Elements: 1 (9) |
Complexity: 2 |
Complexity Density: 0.29 |
|
54 |
2 |
public Repository createGitTestRepository(String repoName) throws Exception... |
55 |
|
{ |
56 |
2 |
File localDirectory = getRepositoryFile(repoName); |
57 |
2 |
File gitDirectory = new File(localDirectory, ".git"); |
58 |
2 |
FileRepositoryBuilder builder = new FileRepositoryBuilder(); |
59 |
2 |
Repository repository = builder.setGitDir(gitDirectory) |
60 |
|
.readEnvironment() |
61 |
|
.findGitDir() |
62 |
|
.build(); |
63 |
2 |
if (!gitDirectory.exists()) { |
64 |
2 |
repository.create(); |
65 |
|
} |
66 |
2 |
return repository; |
67 |
|
} |
68 |
|
|
|
|
| 76.2% |
Uncovered Elements: 5 (21) |
Complexity: 4 |
Complexity Density: 0.27 |
|
69 |
2 |
public void add(File repo, String path, String content, PersonIdent author, PersonIdent committer,... |
70 |
|
String message) throws Exception |
71 |
|
{ |
72 |
2 |
File file = new File(repo.getParentFile(), path); |
73 |
2 |
if (!file.getParentFile().exists()) { |
74 |
0 |
Assert.assertTrue(file.getParentFile().mkdirs()); |
75 |
|
} |
76 |
2 |
if (!file.exists()) { |
77 |
2 |
Assert.assertTrue(file.createNewFile()); |
78 |
|
} |
79 |
2 |
PrintWriter writer = new PrintWriter(file); |
80 |
2 |
if (content == null) |
81 |
0 |
content = ""; |
82 |
2 |
try { |
83 |
2 |
writer.print(content); |
84 |
|
} finally { |
85 |
2 |
writer.close(); |
86 |
|
} |
87 |
2 |
Git git = Git.open(repo); |
88 |
2 |
git.add().addFilepattern(path).call(); |
89 |
2 |
RevCommit commit = git.commit().setOnly(path).setMessage(message).setAuthor(author).setCommitter(committer) |
90 |
|
.call(); |
91 |
2 |
Assert.assertNotNull(commit); |
92 |
|
} |
93 |
|
} |