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

public Class FetchCommand

extends TransportCommand<FetchCommand, FetchResult>
Class Inheritance
Static Imports
java.util.stream.Collectors.toList

A class used to execute a Fetch command. It has setters for all supported options and arguments of this command and a call() method to finally execute the command.
See Also
Git documentation about Fetch

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static interface
FetchCommand.Callback

Callback for status of fetch operation.

Field Summary

Modifier and TypeField and Description
private FetchCommand.Callback
private boolean
private Instant
private Integer
private boolean
private String
private boolean
private ProgressMonitor
private List<RefSpec>
private String
private Boolean
private List<String>
private SubmoduleConfig.FetchRecurseSubmodulesMode
private TagOpt
private boolean
private boolean
Inherited from org.eclipse.jgit.api.TransportCommand:
credentialsProvidertimeouttransportConfigCallback

Constructor Summary

AccessConstructor and Description
protected
FetchCommand(Repository repo)

Constructor for FetchCommand.

Method Summary

Modifier and TypeMethod and Description
public FetchCommand

Returns:

this
addShallowExclude
(String
the ref or commit; must not be null
shallowExclude
)

Deepens or shortens the history of a shallow repository to exclude commits reachable from a specified remote branch or tag.

public FetchCommand

Returns:

this
addShallowExclude
(ObjectId
the commit; must not be null
shallowExclude
)

Creates a shallow clone with a history, excluding commits reachable from a specified remote branch or tag.

private List<RefSpec>
public FetchResult
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.

private void
public ProgressMonitor

Returns:

the progress monitor for the fetch operation
getProgressMonitor
()

Get progress monitor

private SubmoduleConfig.FetchRecurseSubmodulesMode
public List<RefSpec>

Returns:

the ref specs
getRefSpecs
()

Get list of RefSpecs

public String

Returns:

the remote used for the remote operation
getRemote
()

Get the remote

public int

Returns:

the timeout used for the fetch operation
getTimeout
()

Get timeout

public boolean

Returns:

whether to check received objects for validity
isCheckFetchedObjects
()

Whether to check received objects for validity

public boolean

Returns:

the dry run preference for the fetch operation
isDryRun
()

Whether to do a dry run

public boolean

Returns:

whether refs affected by the fetch are updated forcefully
isForceUpdate
()

Whether fetch --force option is enabled

public boolean

Returns:

whether to remove refs which no longer exist in the source
isRemoveDeletedRefs
()

Whether to remove refs which no longer exist in the source

public boolean

Returns:

the thin-pack preference for fetch operation
isThin
()

Get thin-pack preference

public FetchCommand

Returns:

this
setCallback
(FetchCommand.Callback
the callback
callback
)

Register a progress callback.

public FetchCommand

Returns:

this
setCheckFetchedObjects
(boolean
whether to check objects for validity
checkFetchedObjects
)

If set to true, objects received will be checked for validity

public FetchCommand

Returns:

this
setDepth
(int
the depth
depth
)

Limits fetching to the specified number of commits from the tip of each remote branch history.

public FetchCommand

Returns:

this
setDryRun
(boolean
whether to do a dry run
dryRun
)

Sets whether the fetch operation should be a dry run

public FetchCommand

Returns:

this command
setForceUpdate
(boolean
whether to update refs affected by the fetch forcefully
force
)

Set fetch --force option

public FetchCommand

Returns:

this
setInitialBranch
(String
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 passing null or HEAD.
branch
)

Set the initial branch

public FetchCommand

Returns:

this
setProgressMonitor
(ProgressMonitor monitor)

The progress monitor associated with the fetch operation.

public FetchCommand

Returns:

this
setRecurseSubmodules
(SubmoduleConfig.FetchRecurseSubmodulesMode
corresponds to the --recurse-submodules/--no-recurse-submodules options. If null use the value of the submodule.name.fetchRecurseSubmodules option configured per submodule. If not specified there, use the value of the fetch.recurseSubmodules option configured in git config. If not configured in either, "on-demand" is the built-in default.
recurse
)

Set the mode to be used for recursing into submodules.

public FetchCommand

Returns:

this
setRefSpecs
(String...
String representation of RefSpecs
specs
)

The ref specs to be used in the fetch operation

public FetchCommand

Returns:

this
setRefSpecs
(RefSpec... specs)

The ref specs to be used in the fetch operation

public FetchCommand

Returns:

this
setRefSpecs
(List<RefSpec> specs)

The ref specs to be used in the fetch operation

public FetchCommand

Returns:

this
setRemote
(String
name of a remote
remote
)

The remote (uri or name) used for the fetch operation.

public FetchCommand

Returns:

this
setRemoveDeletedRefs
(boolean
whether to remove deleted Refs
removeDeletedRefs
)

If set to true, refs are removed which no longer exist in the source

pack-priv void
setShallowExcludes(List<String> shallowExcludes)

public FetchCommand

Returns:

this
setShallowSince
(OffsetDateTime
the timestammp; must not be null
shallowSince
)

Deepens or shortens the history of a shallow repository to include all reachable commits after a specified time.

public FetchCommand

Returns:

this
setShallowSince
(Instant
the timestammp; must not be null
shallowSince
)

Deepens or shortens the history of a shallow repository to include all reachable commits after a specified time.

public FetchCommand

Returns:

this
setTagOpt
(TagOpt tagOpt)

Sets the specification of annotated tag behavior during fetch

public FetchCommand

Returns:

this
setThin
(boolean
the thin-pack preference
thinPack
)

Sets the thin-pack preference for fetch operation.

public FetchCommand

Returns:

this
setUnshallow
(boolean
whether to unshallow or not
unshallow
)

If the source repository is complete, converts a shallow repository to a complete one, removing all the limitations imposed by shallow repositories.

Inherited from org.eclipse.jgit.api.TransportCommand:
configureconfigureselfsetCredentialsProvidersetTimeoutsetTransportConfigCallback

Field Detail

callbackback to summary
private FetchCommand.Callback callback
checkFetchedObjectsback to summary
private boolean checkFetchedObjects
deepenSinceback to summary
private Instant deepenSince
depthback to summary
private Integer depth
dryRunback to summary
private boolean dryRun
initialBranchback to summary
private String initialBranch
isForceUpdateback to summary
private boolean isForceUpdate
monitorback to summary
private ProgressMonitor monitor
refSpecsback to summary
private List<RefSpec> refSpecs
remoteback to summary
private String remote
removeDeletedRefsback to summary
private Boolean removeDeletedRefs
shallowExcludesback to summary
private List<String> shallowExcludes
submoduleRecurseModeback to summary
private SubmoduleConfig.FetchRecurseSubmodulesMode submoduleRecurseMode
tagOptionback to summary
private TagOpt tagOption
thinback to summary
private boolean thin
unshallowback to summary
private boolean unshallow

Constructor Detail

FetchCommandback to summary
protected FetchCommand(Repository repo)

Constructor for FetchCommand.

Parameters
repo:Repository

a org.eclipse.jgit.lib.Repository object.

Method Detail

addShallowExcludeback to summary
public FetchCommand addShallowExclude(String shallowExclude)

Deepens or shortens the history of a shallow repository to exclude commits reachable from a specified remote branch or tag.

Parameters
shallowExclude:String

the ref or commit; must not be null

Returns:FetchCommand

this

Since
6.3
addShallowExcludeback to summary
public FetchCommand addShallowExclude(ObjectId shallowExclude)

Creates a shallow clone with a history, excluding commits reachable from a specified remote branch or tag.

Parameters
shallowExclude:ObjectId

the commit; must not be null

Returns:FetchCommand

this

Since
6.3
applyOptionsback to summary
private List<RefSpec> applyOptions(List<RefSpec> refSpecs2)
callback to summary
public FetchResult call() throws GitAPIException, InvalidRemoteException, TransportException

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

Execute the fetch command 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 to call())

Returns:FetchResult

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

computed result

Annotations
@Override
fetchSubmodulesback to summary
private void fetchSubmodules(FetchResult results) throws TransportException, GitAPIException, InvalidConfigurationException
getProgressMonitorback to summary
public ProgressMonitor getProgressMonitor()

Get progress monitor

Returns:ProgressMonitor

the progress monitor for the fetch operation

getRecurseModeback to summary
private SubmoduleConfig.FetchRecurseSubmodulesMode getRecurseMode(String path)
getRefSpecsback to summary
public List<RefSpec> getRefSpecs()

Get list of RefSpecs

Returns:List<RefSpec>

the ref specs

getRemoteback to summary
public String getRemote()

Get the remote

Returns:String

the remote used for the remote operation

getTimeoutback to summary
public int getTimeout()

Get timeout

Returns:int

the timeout used for the fetch operation

isCheckFetchedObjectsback to summary
public boolean isCheckFetchedObjects()

Whether to check received objects for validity

Returns:boolean

whether to check received objects for validity

isDryRunback to summary
public boolean isDryRun()

Whether to do a dry run

Returns:boolean

the dry run preference for the fetch operation

isForceUpdateback to summary
public boolean isForceUpdate()

Whether fetch --force option is enabled

Returns:boolean

whether refs affected by the fetch are updated forcefully

Since
5.0
isRemoveDeletedRefsback to summary
public boolean isRemoveDeletedRefs()

Whether to remove refs which no longer exist in the source

Returns:boolean

whether to remove refs which no longer exist in the source

isThinback to summary
public boolean isThin()

Get thin-pack preference

Returns:boolean

the thin-pack preference for fetch operation

setCallbackback to summary
public FetchCommand setCallback(FetchCommand.Callback callback)

Register a progress callback.

Parameters
callback:FetchCommand.Callback

the callback

Returns:FetchCommand

this

Since
4.8
setCheckFetchedObjectsback to summary
public FetchCommand setCheckFetchedObjects(boolean checkFetchedObjects)

If set to true, objects received will be checked for validity

Parameters
checkFetchedObjects:boolean

whether to check objects for validity

Returns:FetchCommand

this

setDepthback to summary
public FetchCommand setDepth(int depth)

Limits fetching to the specified number of commits from the tip of each remote branch history.

Parameters
depth:int

the depth

Returns:FetchCommand

this

Since
6.3
setDryRunback to summary
public FetchCommand setDryRun(boolean dryRun)

Sets whether the fetch operation should be a dry run

Parameters
dryRun:boolean

whether to do a dry run

Returns:FetchCommand

this

setForceUpdateback to summary
public FetchCommand setForceUpdate(boolean force)

Set fetch --force option

Parameters
force:boolean

whether to update refs affected by the fetch forcefully

Returns:FetchCommand

this command

Since
5.0
setInitialBranchback to summary
public FetchCommand setInitialBranch(String branch)

Set the initial branch

Parameters
branch:String

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 passing null or HEAD.

Returns:FetchCommand

this

Since
5.11
setProgressMonitorback to summary
public FetchCommand setProgressMonitor(ProgressMonitor monitor)

The progress monitor associated with the fetch operation. By default, this is set to NullProgressMonitor

Parameters
monitor:ProgressMonitor

a org.eclipse.jgit.lib.ProgressMonitor

Returns:FetchCommand

this

See Also
NullProgressMonitor
setRecurseSubmodulesback to summary
public FetchCommand setRecurseSubmodules(SubmoduleConfig.FetchRecurseSubmodulesMode recurse)

Set the mode to be used for recursing into submodules.

Parameters
recurse:SubmoduleConfig.FetchRecurseSubmodulesMode

corresponds to the --recurse-submodules/--no-recurse-submodules options. If null use the value of the submodule.name.fetchRecurseSubmodules option configured per submodule. If not specified there, use the value of the fetch.recurseSubmodules option configured in git config. If not configured in either, "on-demand" is the built-in default.

Returns:FetchCommand

this

Since
4.7
setRefSpecsback to summary
public FetchCommand setRefSpecs(String... specs)

The ref specs to be used in the fetch operation

Parameters
specs:String[]

String representation of RefSpecs

Returns:FetchCommand

this

Since
4.9
setRefSpecsback to summary
public FetchCommand setRefSpecs(RefSpec... specs)

The ref specs to be used in the fetch operation

Parameters
specs:RefSpec[]

one or multiple org.eclipse.jgit.transport.RefSpecs

Returns:FetchCommand

this

setRefSpecsback to summary
public FetchCommand setRefSpecs(List<RefSpec> specs)

The ref specs to be used in the fetch operation

Parameters
specs:List<RefSpec>

list of org.eclipse.jgit.transport.RefSpecs

Returns:FetchCommand

this

setRemoteback to summary
public FetchCommand setRemote(String remote)

The remote (uri or name) used for the fetch operation. If no remote is set, the default value of Constants.DEFAULT_REMOTE_NAME will be used.

Parameters
remote:String

name of a remote

Returns:FetchCommand

this

See Also
Constants#DEFAULT_REMOTE_NAME
setRemoveDeletedRefsback to summary
public FetchCommand setRemoveDeletedRefs(boolean removeDeletedRefs)

If set to true, refs are removed which no longer exist in the source

Parameters
removeDeletedRefs:boolean

whether to remove deleted Refs

Returns:FetchCommand

this

setShallowExcludesback to summary
pack-priv void setShallowExcludes(List<String> shallowExcludes)
setShallowSinceback to summary
public FetchCommand setShallowSince(OffsetDateTime shallowSince)

Deepens or shortens the history of a shallow repository to include all reachable commits after a specified time.

Parameters
shallowSince:OffsetDateTime

the timestammp; must not be null

Returns:FetchCommand

this

Since
6.3
setShallowSinceback to summary
public FetchCommand setShallowSince(Instant shallowSince)

Deepens or shortens the history of a shallow repository to include all reachable commits after a specified time.

Parameters
shallowSince:Instant

the timestammp; must not be null

Returns:FetchCommand

this

Since
6.3
setTagOptback to summary
public FetchCommand setTagOpt(TagOpt tagOpt)

Sets the specification of annotated tag behavior during fetch

Parameters
tagOpt:TagOpt

the org.eclipse.jgit.transport.TagOpt

Returns:FetchCommand

this

setThinback to summary
public FetchCommand setThin(boolean thinPack)

Sets the thin-pack preference for fetch operation. Default setting is Transport.DEFAULT_FETCH_THIN

Parameters
thinPack:boolean

the thin-pack preference

Returns:FetchCommand

this

setUnshallowback to summary
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:boolean

whether to unshallow or not

Returns:FetchCommand

this

Since
6.3
org.eclipse.jgit.api back to summary

public Interface FetchCommand.Callback


Callback for status of fetch operation.
Since
4.8

Method Summary

Modifier and TypeMethod and Description
public void
fetchingSubmodule(String
the submodule name.
name
)

Notify fetching a submodule.

Method Detail

fetchingSubmoduleback to summary
public void fetchingSubmodule(String name)

Notify fetching a submodule.

Parameters
name:String

the submodule name.