James Moger
2011-04-04 5fe7df81eb38dc66f2cfc4bf1973863a19f55cf2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package com.gitblit;
 
import java.io.File;
 
import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.api.InitCommand;
 
import com.beust.jcommander.JCommander;
import com.beust.jcommander.Parameter;
import com.beust.jcommander.ParameterException;
import com.beust.jcommander.Parameters;
 
public class MakeRepository {
 
    public static void main(String... args) throws Exception {
        Params params = new Params();
        JCommander jc = new JCommander(params);
        try {
            jc.parse(args);
            if (params.help)
                jc.usage();
        } catch (ParameterException t) {
            jc.usage();
        }
 
        File directory = new File(params.create);
        InitCommand init = new InitCommand();
        init.setDirectory(directory);
        init.setBare(true);
        Git git = init.call();
        git.getRepository().close();
        System.out.println("GIT repository " + directory.getCanonicalPath() + " created.");
    }
 
    @Parameters(separators = " ")
    private static class Params {
 
        /*
         * Help/Usage
         */
        @Parameter(names = { "-h", "--help" }, description = "Show this help")
        public Boolean help = false;
 
        /*
         * Repository to Create
         */
        @Parameter(names = { "--create" }, description = "GIT Repository to Create", required = true)
        public String create = "";
 
    }
}