Top Description Fields Constructors Methods
org.eclipse.jgit.api

public Class AddCommand

extends GitCommand<DirCache>
Class Inheritance
Static Imports
org.eclipse.jgit.lib.Constants.OBJ_BLOB, .FileMode.GITLINK, .FileMode.TYPE_GITLINK, .FileMode.TYPE_TREE

A class used to execute a Add command. It has setters for all supported options and arguments of this command and a call() method to finally execute the command. Each instance of this class should only be used for one invocation of the command (means: one call to call())
See Also
Git documentation about Add

Field Summary

Modifier and TypeField and Description
private Boolean
private List<String>
private boolean
private boolean
private WorkingTreeIterator
Inherited from org.eclipse.jgit.api.GitCommand:
repo

Constructor Summary

AccessConstructor and Description
public
AddCommand(Repository repo)

Constructor for AddCommand

Method Summary

Modifier and TypeMethod and Description
public AddCommand

Returns:

this
addFilepattern
(String
repository-relative path of file/directory to add (with / as separator)
filepattern
)

Add a path to a file/directory whose content should be added.

public DirCache
call()

Implements abstract org.eclipse.jgit.api.GitCommand.call.

Implements java.util.concurrent.Callable.call.

Computes a result, or throws an exception if unable to do so.

public boolean

Returns:

true if it was set; false otherwise
isAll
()

Tells whether '--all' has been set for this command.

public boolean

Returns:

whether files will be renormalized
isRenormalize
()

Tells whether the command will renormalize by re-applying the "clean" process to tracked files.

public boolean

Returns:

whether to only match against already tracked files
isUpdate
()

Whether to only match against already tracked files

public AddCommand

Returns:

this
setAll
(boolean
whether to enable '--all' mode
all
)

Defines whether the command will use '--all' mode: update existing index entries, add new entries, and remove index entries for which there is no file.

public AddCommand

Returns:

this
setRenormalize
(boolean
whether to renormalize tracked files
renormalize
)

Defines whether the command will renormalize by re-applying the "clean" process to tracked files.

public AddCommand

Returns:

this
setUpdate
(boolean
If set to true, the command only matches filepattern against already tracked files in the index rather than the working tree. That means that it will never stage new files, but that it will stage modified new contents of tracked files and that it will remove files from the index if the corresponding files in the working tree have been removed. In contrast to the git command line a filepattern must exist also if update is set to true as there is no concept of a working directory here.
update
)

Set whether to only match against already tracked files.

public AddCommand

Returns:

this
setWorkingTreeIterator
(WorkingTreeIterator f)

Allow clients to provide their own implementation of a FileTreeIterator

Inherited from org.eclipse.jgit.api.GitCommand:
checkCallablegetRepositorysetCallable

Field Detail

allback to summary
private Boolean all
filepatternsback to summary
private List<String> filepatterns
renormalizeback to summary
private boolean renormalize
updateback to summary
private boolean update
workingTreeIteratorback to summary
private WorkingTreeIterator workingTreeIterator

Constructor Detail

AddCommandback to summary
public AddCommand(Repository repo)

Constructor for AddCommand

Parameters
repo:Repository

the org.eclipse.jgit.lib.Repository

Method Detail

addFilepatternback to summary
public AddCommand addFilepattern(String filepattern)

Add a path to a file/directory whose content should be added.

A directory name (e.g. dir to add dir/file1 and dir/file2) can also be given to add all files in the directory, recursively. Fileglobs (e.g. *.c) are not yet supported.

If a pattern "." is added, all changes in the git repository's working tree will be added.

File patterns are required unless isUpdate() == true or setAll(boolean) is called. If so and no file patterns are given, all changes will be added (i.e., a file pattern of "." is implied).

Parameters
filepattern:String

repository-relative path of file/directory to add (with / as separator)

Returns:AddCommand

this

callback to summary
public DirCache call() throws GitAPIException, NoFilepatternException

Implements abstract org.eclipse.jgit.api.GitCommand.call.

Implements java.util.concurrent.Callable.call.

Doc from org.eclipse.jgit.api.GitCommand.call.

Computes a result, or throws an exception if unable to do so.

Execute the command

Executes the Add command. Each instance of this class should only be used for one invocation of the command. Don't call this method twice on an instance.

Returns:DirCache

Doc from java.util.concurrent.Callable.call.

computed result

Annotations
@Override
Exceptions
NoFilepatternException:
if no file patterns are given if isUpdate() == false and setAll(boolean) was not called
JGitInternalException:
on errors, but also if isUpdate() == true _and_ setAll(boolean) had been called
isAllback to summary
public boolean isAll()

Tells whether '--all' has been set for this command.

Returns:boolean

true if it was set; false otherwise

Since
7.2
isRenormalizeback to summary
public boolean isRenormalize()

Tells whether the command will renormalize by re-applying the "clean" process to tracked files.

For legacy reasons, this is true by default.

This setting is independent of isUpdate(). In C git, command-line option --renormalize implies --update.

Returns:boolean

whether files will be renormalized

Since
6.6
isUpdateback to summary
public boolean isUpdate()

Whether to only match against already tracked files

Returns:boolean

whether to only match against already tracked files

setAllback to summary
public AddCommand setAll(boolean all)

Defines whether the command will use '--all' mode: update existing index entries, add new entries, and remove index entries for which there is no file. (In other words: also stage deletions.)

The setting is independent of setUpdate(boolean).

Parameters
all:boolean

whether to enable '--all' mode

Returns:AddCommand

this

Since
7.2
setRenormalizeback to summary
public AddCommand setRenormalize(boolean renormalize)

Defines whether the command will renormalize by re-applying the "clean" process to tracked files.

This does not automatically call setUpdate(boolean).

Parameters
renormalize:boolean

whether to renormalize tracked files

Returns:AddCommand

this

Since
6.6
setUpdateback to summary
public AddCommand setUpdate(boolean update)

Set whether to only match against already tracked files. If update == true, re-sets a previous setAll(boolean).

Parameters
update:boolean

If set to true, the command only matches filepattern against already tracked files in the index rather than the working tree. That means that it will never stage new files, but that it will stage modified new contents of tracked files and that it will remove files from the index if the corresponding files in the working tree have been removed. In contrast to the git command line a filepattern must exist also if update is set to true as there is no concept of a working directory here.

Returns:AddCommand

this

setWorkingTreeIteratorback to summary
public AddCommand setWorkingTreeIterator(WorkingTreeIterator f)

Allow clients to provide their own implementation of a FileTreeIterator

Parameters
f:WorkingTreeIterator

a org.eclipse.jgit.treewalk.WorkingTreeIterator object.

Returns:AddCommand

this