1
2
3
4
5
6
7
8
9
10
11 package org.eclipse.jgit.pgm;
12
13 import java.util.ArrayList;
14 import java.util.List;
15
16 import org.eclipse.jgit.api.AddCommand;
17 import org.eclipse.jgit.api.Git;
18 import org.eclipse.jgit.api.errors.GitAPIException;
19 import org.kohsuke.args4j.Argument;
20 import org.kohsuke.args4j.Option;
21
22 @Command(common = true, usage = "usage_addFileContentsToTheIndex")
23 class Add extends TextBuiltin {
24
25 @Option(name = "--update", aliases = { "-u" }, usage = "usage_onlyMatchAgainstAlreadyTrackedFiles")
26 private boolean update = false;
27
28 @Argument(required = true, metaVar = "metaVar_filepattern", usage = "usage_filesToAddContentFrom")
29 private List<String> filepatterns = new ArrayList<>();
30
31
32 @Override
33 protected void run() throws Exception {
34 try (Gitit.html#Git">Git git = new Git(db)) {
35 AddCommand addCmd = git.add();
36 addCmd.setUpdate(update);
37 for (String p : filepatterns)
38 addCmd.addFilepattern(p);
39 addCmd.call();
40 } catch (GitAPIException e) {
41 throw die(e.getMessage(), e);
42 }
43 }
44 }