View Javadoc
1   /*
2    * Copyright (C) 2010, Sasa Zivkov <sasa.zivkov@sap.com> and others
3    *
4    * This program and the accompanying materials are made available under the
5    * terms of the Eclipse Distribution License v. 1.0 which is available at
6    * https://www.eclipse.org/org/documents/edl-v10.php.
7    *
8    * SPDX-License-Identifier: BSD-3-Clause
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  	/** {@inheritDoc} */
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  }