1
2
3
4
5
6
7
8
9
10 package org.eclipse.jgit.ant.tasks;
11
12 import java.io.File;
13
14 import org.apache.tools.ant.BuildException;
15 import org.apache.tools.ant.Task;
16 import org.eclipse.jgit.api.Git;
17 import org.eclipse.jgit.api.InitCommand;
18
19
20
21
22
23
24
25 public class GitInitTask extends Task {
26 private File destination;
27 private boolean bare;
28
29
30
31
32
33
34
35
36 public void setDest(File dest) {
37 this.destination = dest;
38 }
39
40
41
42
43
44
45
46
47 public void setBare(boolean bare) {
48 this.bare = bare;
49 }
50
51
52 @Override
53 public void execute() throws BuildException {
54 if (bare) {
55 log("Initializing bare repository at " + destination);
56 } else {
57 log("Initializing repository at " + destination);
58 }
59 try {
60 InitCommand init = Git.init();
61 init.setBare(bare).setDirectory(destination);
62 init.call();
63 } catch (Exception e) {
64 throw new BuildException("Could not initialize repository", e);
65 }
66 }
67 }