- java.lang.Object
-
- org.eclipse.jgit.api.GitCommand<T>
-
- org.eclipse.jgit.api.TransportCommand<FetchCommand,FetchResult>
-
- org.eclipse.jgit.api.FetchCommand
-
- All Implemented Interfaces:
Callable<FetchResult>
public class FetchCommand extends TransportCommand<FetchCommand,FetchResult>
A class used to execute aFetchcommand. It has setters for all supported options and arguments of this command and acall()method to finally execute the command.- See Also:
- Git documentation about Fetch
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceFetchCommand.CallbackCallback for status of fetch operation.
-
Field Summary
-
Fields inherited from class org.eclipse.jgit.api.TransportCommand
credentialsProvider, timeout, transportConfigCallback
-
Fields inherited from class org.eclipse.jgit.api.GitCommand
repo
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedFetchCommand(Repository repo)Constructor for FetchCommand.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description FetchCommandaddShallowExclude(String shallowExclude)Deepens or shortens the history of a shallow repository to exclude commits reachable from a specified remote branch or tag.FetchCommandaddShallowExclude(ObjectId shallowExclude)Creates a shallow clone with a history, excluding commits reachable from a specified remote branch or tag.FetchResultcall()ProgressMonitorgetProgressMonitor()Get progress monitorList<RefSpec>getRefSpecs()Get list ofRefSpecsStringgetRemote()Get the remoteintgetTimeout()Get timeoutbooleanisCheckFetchedObjects()Whether to check received objects for validitybooleanisDryRun()Whether to do a dry runbooleanisForceUpdate()Whether fetch --force option is enabledbooleanisRemoveDeletedRefs()Whether to remove refs which no longer exist in the sourcebooleanisThin()Get thin-pack preferenceFetchCommandsetCallback(FetchCommand.Callback callback)Register a progress callback.FetchCommandsetCheckFetchedObjects(boolean checkFetchedObjects)If set totrue, objects received will be checked for validityFetchCommandsetDepth(int depth)Limits fetching to the specified number of commits from the tip of each remote branch history.FetchCommandsetDryRun(boolean dryRun)Sets whether the fetch operation should be a dry runFetchCommandsetForceUpdate(boolean force)Set fetch --force optionFetchCommandsetInitialBranch(String branch)Set the initial branchFetchCommandsetProgressMonitor(ProgressMonitor monitor)The progress monitor associated with the fetch operation.FetchCommandsetRecurseSubmodules(SubmoduleConfig.FetchRecurseSubmodulesMode recurse)Set the mode to be used for recursing into submodules.FetchCommandsetRefSpecs(String... specs)The ref specs to be used in the fetch operationFetchCommandsetRefSpecs(List<RefSpec> specs)The ref specs to be used in the fetch operationFetchCommandsetRefSpecs(RefSpec... specs)The ref specs to be used in the fetch operationFetchCommandsetRemote(String remote)The remote (uri or name) used for the fetch operation.FetchCommandsetRemoveDeletedRefs(boolean removeDeletedRefs)If set totrue, refs are removed which no longer exist in the sourceFetchCommandsetShallowSince(Instant shallowSince)Deepens or shortens the history of a shallow repository to include all reachable commits after a specified time.FetchCommandsetShallowSince(OffsetDateTime shallowSince)Deepens or shortens the history of a shallow repository to include all reachable commits after a specified time.FetchCommandsetTagOpt(TagOpt tagOpt)Sets the specification of annotated tag behavior during fetchFetchCommandsetThin(boolean thin)Sets the thin-pack preference for fetch operation.FetchCommandsetUnshallow(boolean unshallow)If the source repository is complete, converts a shallow repository to a complete one, removing all the limitations imposed by shallow repositories.-
Methods inherited from class org.eclipse.jgit.api.TransportCommand
configure, configure, self, setCredentialsProvider, setTimeout, setTransportConfigCallback
-
Methods inherited from class org.eclipse.jgit.api.GitCommand
checkCallable, getRepository, setCallable
-
-
-
-
Constructor Detail
-
FetchCommand
protected FetchCommand(Repository repo)
Constructor for FetchCommand.- Parameters:
repo- aRepositoryobject.
-
-
Method Detail
-
call
public FetchResult call() throws GitAPIException, InvalidRemoteException, TransportException
Execute the command
Execute the
fetchcommand with all the options and parameters collected by the setter methods of this class. Each instance of this class should only be used for one invocation of the command (means: one call tocall())- Specified by:
callin interfaceCallable<FetchResult>- Specified by:
callin classGitCommand<FetchResult>- Throws:
GitAPIExceptionInvalidRemoteExceptionTransportException
-
setRecurseSubmodules
public FetchCommand setRecurseSubmodules(@Nullable SubmoduleConfig.FetchRecurseSubmodulesMode recurse)
Set the mode to be used for recursing into submodules.- Parameters:
recurse- corresponds to the --recurse-submodules/--no-recurse-submodules options. Ifnulluse the value of thesubmodule.name.fetchRecurseSubmodulesoption configured per submodule. If not specified there, use the value of thefetch.recurseSubmodulesoption configured in git config. If not configured in either, "on-demand" is the built-in default.- Returns:
this- Since:
- 4.7
-
setRemote
public FetchCommand setRemote(String remote)
The remote (uri or name) used for the fetch operation. If no remote is set, the default value ofConstants.DEFAULT_REMOTE_NAMEwill be used.- Parameters:
remote- name of a remote- Returns:
this- See Also:
Constants.DEFAULT_REMOTE_NAME
-
getRemote
public String getRemote()
Get the remote- Returns:
- the remote used for the remote operation
-
getTimeout
public int getTimeout()
Get timeout- Returns:
- the timeout used for the fetch operation
-
isCheckFetchedObjects
public boolean isCheckFetchedObjects()
Whether to check received objects for validity- Returns:
- whether to check received objects for validity
-
setCheckFetchedObjects
public FetchCommand setCheckFetchedObjects(boolean checkFetchedObjects)
If set totrue, objects received will be checked for validity- Parameters:
checkFetchedObjects- whether to check objects for validity- Returns:
this
-
isRemoveDeletedRefs
public boolean isRemoveDeletedRefs()
Whether to remove refs which no longer exist in the source- Returns:
- whether to remove refs which no longer exist in the source
-
setRemoveDeletedRefs
public FetchCommand setRemoveDeletedRefs(boolean removeDeletedRefs)
If set totrue, refs are removed which no longer exist in the source- Parameters:
removeDeletedRefs- whether to remove deletedRefs- Returns:
this
-
getProgressMonitor
public ProgressMonitor getProgressMonitor()
Get progress monitor- Returns:
- the progress monitor for the fetch operation
-
setProgressMonitor
public FetchCommand setProgressMonitor(ProgressMonitor monitor)
The progress monitor associated with the fetch operation. By default, this is set toNullProgressMonitor- Parameters:
monitor- aProgressMonitor- Returns:
this- See Also:
NullProgressMonitor
-
setRefSpecs
public FetchCommand setRefSpecs(String... specs)
The ref specs to be used in the fetch operation- Parameters:
specs- String representation ofRefSpecs- Returns:
this- Since:
- 4.9
-
setRefSpecs
public FetchCommand setRefSpecs(RefSpec... specs)
The ref specs to be used in the fetch operation- Parameters:
specs- one or multipleRefSpecs- Returns:
this
-
setRefSpecs
public FetchCommand setRefSpecs(List<RefSpec> specs)
The ref specs to be used in the fetch operation- Parameters:
specs- list ofRefSpecs- Returns:
this
-
isDryRun
public boolean isDryRun()
Whether to do a dry run- Returns:
- the dry run preference for the fetch operation
-
setDryRun
public FetchCommand setDryRun(boolean dryRun)
Sets whether the fetch operation should be a dry run- Parameters:
dryRun- whether to do a dry run- Returns:
this
-
isThin
public boolean isThin()
Get thin-pack preference- Returns:
- the thin-pack preference for fetch operation
-
setThin
public FetchCommand setThin(boolean thin)
Sets the thin-pack preference for fetch operation. Default setting is Transport.DEFAULT_FETCH_THIN- Parameters:
thin- the thin-pack preference- Returns:
this
-
setTagOpt
public FetchCommand setTagOpt(TagOpt tagOpt)
Sets the specification of annotated tag behavior during fetch- Parameters:
tagOpt- theTagOpt- Returns:
this
-
setInitialBranch
public FetchCommand setInitialBranch(String branch)
Set the initial branch- Parameters:
branch- the initial branch to check out when cloning the repository. Can be specified as ref name (refs/heads/master), branch name (master) or tag name (v1.2.3). The default is to use the branch pointed to by the cloned repository's HEAD and can be requested by passingnullorHEAD.- Returns:
this- Since:
- 5.11
-
setCallback
public FetchCommand setCallback(FetchCommand.Callback callback)
Register a progress callback.- Parameters:
callback- the callback- Returns:
this- Since:
- 4.8
-
isForceUpdate
public boolean isForceUpdate()
Whether fetch --force option is enabled- Returns:
- whether refs affected by the fetch are updated forcefully
- Since:
- 5.0
-
setForceUpdate
public FetchCommand setForceUpdate(boolean force)
Set fetch --force option- Parameters:
force- whether to update refs affected by the fetch forcefully- Returns:
- this command
- Since:
- 5.0
-
setDepth
public FetchCommand setDepth(int depth)
Limits fetching to the specified number of commits from the tip of each remote branch history.- Parameters:
depth- the depth- Returns:
this- Since:
- 6.3
-
setShallowSince
public FetchCommand setShallowSince(@NonNull OffsetDateTime shallowSince)
Deepens or shortens the history of a shallow repository to include all reachable commits after a specified time.- Parameters:
shallowSince- the timestammp; must not benull- Returns:
this- Since:
- 6.3
-
setShallowSince
public FetchCommand setShallowSince(@NonNull Instant shallowSince)
Deepens or shortens the history of a shallow repository to include all reachable commits after a specified time.- Parameters:
shallowSince- the timestammp; must not benull- Returns:
this- Since:
- 6.3
-
addShallowExclude
public FetchCommand addShallowExclude(@NonNull String shallowExclude)
Deepens or shortens the history of a shallow repository to exclude commits reachable from a specified remote branch or tag.- Parameters:
shallowExclude- the ref or commit; must not benull- Returns:
this- Since:
- 6.3
-
addShallowExclude
public FetchCommand addShallowExclude(@NonNull ObjectId shallowExclude)
Creates a shallow clone with a history, excluding commits reachable from a specified remote branch or tag.- Parameters:
shallowExclude- the commit; must not benull- Returns:
this- Since:
- 6.3
-
setUnshallow
public FetchCommand setUnshallow(boolean unshallow)
If the source repository is complete, converts a shallow repository to a complete one, removing all the limitations imposed by shallow repositories. If the source repository is shallow, fetches as much as possible so that the current repository has the same history as the source repository.- Parameters:
unshallow- whether to unshallow or not- Returns:
this- Since:
- 6.3
-
-