1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.eclipse.jgit.pgm;
17
18 import java.io.File;
19 import java.io.IOException;
20 import java.text.MessageFormat;
21
22 import org.eclipse.jgit.api.Git;
23 import org.eclipse.jgit.api.InitCommand;
24 import org.eclipse.jgit.api.errors.GitAPIException;
25 import org.eclipse.jgit.lib.Repository;
26 import org.eclipse.jgit.pgm.internal.CLIText;
27 import org.kohsuke.args4j.Argument;
28 import org.kohsuke.args4j.Option;
29
30 @Command(common = true, usage = "usage_CreateAnEmptyGitRepository")
31 class Init extends TextBuiltin {
32 @Option(name = "--bare", usage = "usage_CreateABareRepository")
33 private boolean bare;
34
35 @Argument(index = 0, metaVar = "metaVar_directory")
36 private String directory;
37
38
39 @Override
40 protected final boolean requiresRepository() {
41 return false;
42 }
43
44
45 @Override
46 protected void run() {
47 InitCommand command = Git.init();
48 command.setBare(bare);
49 if (gitdir != null) {
50 command.setDirectory(new File(gitdir));
51 }
52 if (directory != null) {
53 command.setDirectory(new File(directory));
54 }
55 Repository repository;
56 try {
57 repository = command.call().getRepository();
58 outw.println(MessageFormat.format(
59 CLIText.get().initializedEmptyGitRepositoryIn,
60 repository.getDirectory().getAbsolutePath()));
61 } catch (GitAPIException | IOException e) {
62 throw die(e.getMessage(), e);
63 }
64 }
65 }