1
2
3
4
5
6
7
8
9
10
11
12
13 package org.eclipse.jgit.pgm;
14
15 import java.io.IOException;
16 import java.util.ArrayList;
17 import java.util.List;
18
19 import org.eclipse.jgit.lib.ObjectId;
20 import org.eclipse.jgit.lib.Ref;
21 import org.eclipse.jgit.pgm.internal.CLIText;
22 import org.eclipse.jgit.pgm.opt.CmdLineParser;
23 import org.kohsuke.args4j.Argument;
24 import org.kohsuke.args4j.CmdLineException;
25 import org.kohsuke.args4j.Option;
26
27 @Command(usage = "usage_RevParse")
28 class RevParse extends TextBuiltin {
29 @Option(name = "--all", usage = "usage_RevParseAll")
30 boolean all;
31
32 @Option(name = "--verify", usage = "usage_RevParseVerify")
33 boolean verify;
34
35 @Argument(index = 0, metaVar = "metaVar_commitish")
36 private List<ObjectId> commits = new ArrayList<>();
37
38
39 @Override
40 protected void run() {
41 try {
42 if (all) {
43 for (Ref r : db.getRefDatabase().getRefs()) {
44 ObjectId objectId = r.getObjectId();
45
46
47 if (objectId == null) {
48 throw new NullPointerException();
49 }
50 outw.println(objectId.name());
51 }
52 } else {
53 if (verify && commits.size() > 1) {
54 final CmdLineParser clp = new CmdLineParser(this);
55 throw new CmdLineException(clp,
56 CLIText.format(CLIText.get().needSingleRevision));
57 }
58
59 for (ObjectId o : commits) {
60 outw.println(o.name());
61 }
62 }
63 } catch (IOException | CmdLineException e) {
64 throw die(e.getMessage(), e);
65 }
66 }
67 }