Class Transport
- All Implemented Interfaces:
AutoCloseable
- Direct Known Subclasses:
HttpTransport
,TcpTransport
,TestProtocol.TransportInternal
,TransportBundleFile
,TransportBundleStream
,TransportLocal
A transport can be used for either fetching (copying objects into the caller's repository from the remote repository) or pushing (copying objects into the remote repository from the caller's repository). Each transport implementation is responsible for the details associated with establishing the network connection(s) necessary for the copy, as well as actually shuffling data back and forth.
Transport instances and the connections they create are not thread-safe. Callers must ensure a transport is accessed by only one thread at a time.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enum
Type of operation a Transport is being opened for. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate CredentialsProvider
Assists with authentication the connection.static final boolean
Default setting forfetchThin
option.static final boolean
Default setting forpushThin
option.private boolean
Should push just check for operation result, not really push.Specifications to apply during fetch.private boolean
Should fetch request thin-pack if remote repository can produce it.private FilterSpec
private PrintStream
protected final Repository
The repository this transport fetches into, or pushes out of.private ObjectChecker
Should an incoming (fetch) transfer validate objects?private String
Name of the receive pack program, if it must be executed.private String
Name of the upload pack program, if it must be executed.private PackConfig
Pack configuration used by this transport to make pack file.private PrePushHook
(package private) TransferConfig.ProtocolVersion
private static final List<WeakReference<TransportProtocol>>
Specifications to apply during push.private boolean
Should push be all-or-nothing atomic behavior?The option strings associated with the push operation.private boolean
Should push produce thin-pack when sending objects to remote repository.static final RefSpec
Specification for push operation, to push all refs under refs/heads.static final RefSpec
Specification for fetch or push operations, to fetch or push all tags.private boolean
Should refs no longer on the source be pruned from the destination?private TagOpt
Howfetch(ProgressMonitor, Collection)
should handle tags.private int
Timeout in seconds to wait before aborting an IO read or write.protected final URIish
The URI used to create this transport. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
Transport
(Repository local, URIish uri) Create a new transport instance.protected
Create a minimal transport instance not tied to a single repository. -
Method Summary
Modifier and TypeMethodDescriptionvoid
applyConfig
(RemoteConfig cfg) Apply provided remote configuration on this transport.private static Enumeration<URL>
catalogs
(ClassLoader ldr) abstract void
close()
private static boolean
doesNotExist
(RemoteConfig cfg) private static Collection<RefSpec>
expandPushWildcardsFor
(Repository db, Collection<RefSpec> specs) fetch
(ProgressMonitor monitor, Collection<RefSpec> toFetch) Fetch objects and refs from the remote repository to the local one.fetch
(ProgressMonitor monitor, Collection<RefSpec> toFetch, String branch) Fetch objects and refs from the remote repository to the local one.findRemoteRefUpdatesFor
(Collection<RefSpec> specs) Convert push remote refs update specification fromRefSpec
form toRemoteRefUpdate
.findRemoteRefUpdatesFor
(Collection<RefSpec> specs, Map<String, RefLeaseSpec> leases) Convert push remote refs update specification fromRefSpec
form toRemoteRefUpdate
.static Collection<RemoteRefUpdate>
findRemoteRefUpdatesFor
(Repository db, Collection<RefSpec> specs, Collection<RefSpec> fetchSpecs) Convert push remote refs update specification fromRefSpec
form toRemoteRefUpdate
.static Collection<RemoteRefUpdate>
findRemoteRefUpdatesFor
(Repository db, Collection<RefSpec> specs, Map<String, RefLeaseSpec> leases, Collection<RefSpec> fetchSpecs) Convert push remote refs update specification fromRefSpec
form toRemoteRefUpdate
.(package private) static String
findTrackingRefName
(String remoteName, Collection<RefSpec> fetchSpecs) The configured credentials provider.final long
Deprecated.final FilterSpec
Get configured object checker for received objectsDefault setting is:RemoteConfig.DEFAULT_RECEIVE_PACK
Get the name of the remote executable providing upload-pack service.Get the configuration used by the pack generator to make packs.Get the option strings associated with the push operationGet the description of how annotated tags should be treated during fetch.int
Get timeout (in seconds) before aborting an IO operation.static List<TransportProtocol>
Obtain a copy of the registered protocols.getURI()
Get the URI this transport connects to.getURIs
(RemoteConfig cfg, Transport.Operation op) boolean
Whether fetch will verify if received objects are formatted correctly.boolean
isDryRun()
Whether push operation should just check for possible result and not really update remote refsboolean
Default setting is:DEFAULT_FETCH_THIN
boolean
Default setting is false.boolean
Default setting is: falseboolean
Whether destination refs should be removed if they no longer exist at the source repository.private static void
load
(ClassLoader ldr, String cn) static Transport
open
(Repository local, String remote) Open a new transport instance to connect two repositories.static Transport
open
(Repository local, String remote, Transport.Operation op) Open a new transport instance to connect two repositories.static Transport
open
(Repository local, RemoteConfig cfg) Open a new transport instance to connect two repositories.static Transport
open
(Repository local, RemoteConfig cfg, Transport.Operation op) Open a new transport instance to connect two repositories.static Transport
open
(Repository local, URIish uri) Open a new transport instance to connect two repositories.static Transport
open
(Repository local, URIish uri, String remoteName) Open a new transport instance to connect two repositories.static Transport
Open a new transport with no local repository.openAll
(Repository local, String remote) Open new transport instances to connect two repositories.openAll
(Repository local, String remote, Transport.Operation op) Open new transport instances to connect two repositories.openAll
(Repository local, RemoteConfig cfg) Open new transport instances to connect two repositories.openAll
(Repository local, RemoteConfig cfg, Transport.Operation op) Open new transport instances to connect two repositories.abstract FetchConnection
Begins a new connection for fetching from the remote repository.openFetch
(Collection<RefSpec> refSpecs, String... additionalPatterns) Begins a new connection for fetching from the remote repository.abstract PushConnection
openPush()
Begins a new connection for pushing into the remote repository.push
(ProgressMonitor monitor, Collection<RemoteRefUpdate> toPush) Push objects and refs from the local repository to the remote one.push
(ProgressMonitor monitor, Collection<RemoteRefUpdate> toPush, OutputStream out) Push objects and refs from the local repository to the remote one.static void
register
(TransportProtocol proto) Register a TransportProtocol instance for use during open.private static void
private static void
scan
(ClassLoader ldr, URL url) void
setCheckFetchedObjects
(boolean check) Configure if checking received objects is enabledvoid
setCredentialsProvider
(CredentialsProvider credentialsProvider) A credentials provider to assist with authentication connections..void
setDryRun
(boolean dryRun) Set dry run option for push operation.void
setFetchThin
(boolean fetchThin) Set the thin-pack preference for fetch operation.final void
setFilterBlobLimit
(long bytes) Deprecated.UsesetFilterSpec(FilterSpec)
insteadfinal void
setFilterSpec
(FilterSpec filter) void
Set the object checker to verify each received object withvoid
setOptionReceivePack
(String optionReceivePack) Set remote executable providing receive-pack service for pack transports.void
setOptionUploadPack
(String where) Set the name of the remote executable providing upload-pack services.void
Set the configuration used by the pack generator.void
setPushAtomic
(boolean atomic) Request atomic push (all references succeed, or none do).void
setPushOptions
(List<String> pushOptions) Sets the option strings associated with the push operation.void
setPushThin
(boolean pushThin) Set thin-pack preference for push operation.void
setRemoveDeletedRefs
(boolean remove) Set whether or not to remove refs which no longer exist in the source.void
Set the description of how annotated tags should be treated on fetch.void
setTimeout
(int seconds) Set the timeout before willing to abort an IO call.static void
unregister
(TransportProtocol proto) Unregister a TransportProtocol instance.
-
Field Details
-
protocols
-
DEFAULT_FETCH_THIN
public static final boolean DEFAULT_FETCH_THINDefault setting forfetchThin
option.- See Also:
-
DEFAULT_PUSH_THIN
public static final boolean DEFAULT_PUSH_THINDefault setting forpushThin
option.- See Also:
-
REFSPEC_TAGS
Specification for fetch or push operations, to fetch or push all tags. Acts as --tags. -
REFSPEC_PUSH_ALL
Specification for push operation, to push all refs under refs/heads. Acts as --all. -
local
The repository this transport fetches into, or pushes out of. -
uri
The URI used to create this transport. -
optionUploadPack
Name of the upload pack program, if it must be executed. -
fetch
Specifications to apply during fetch. -
tagopt
Howfetch(ProgressMonitor, Collection)
should handle tags.We default to
TagOpt.NO_TAGS
so as to avoid fetching annotated tags during one-shot fetches used for later merges. This prevents dragging down tags from repositories that we do not have established tracking branches for. If we do not track the source repository, we most likely do not care about any tags it publishes. -
fetchThin
private boolean fetchThinShould fetch request thin-pack if remote repository can produce it. -
optionReceivePack
Name of the receive pack program, if it must be executed. -
push
Specifications to apply during push. -
pushThin
private boolean pushThinShould push produce thin-pack when sending objects to remote repository. -
pushAtomic
private boolean pushAtomicShould push be all-or-nothing atomic behavior? -
dryRun
private boolean dryRunShould push just check for operation result, not really push. -
objectChecker
Should an incoming (fetch) transfer validate objects? -
removeDeletedRefs
private boolean removeDeletedRefsShould refs no longer on the source be pruned from the destination? -
filterSpec
-
timeout
private int timeoutTimeout in seconds to wait before aborting an IO read or write. -
packConfig
Pack configuration used by this transport to make pack file. -
credentialsProvider
Assists with authentication the connection. -
pushOptions
The option strings associated with the push operation. -
hookOutRedirect
-
prePush
-
protocol
-
-
Constructor Details
-
Transport
Create a new transport instance.- Parameters:
local
- the repository this instance will fetch into, or push out of. This must be the repository passed toopen(Repository, URIish)
.uri
- the URI used to access the remote repository. This must be the URI passed toopen(Repository, URIish)
.
-
Transport
Create a minimal transport instance not tied to a single repository.- Parameters:
uri
- aURIish
object.
-
-
Method Details
-
registerByService
private static void registerByService() -
catalogs
-
scan
-
load
-
register
Register a TransportProtocol instance for use during open.Protocol definitions are held by WeakReference, allowing them to be garbage collected when the calling application drops all strongly held references to the TransportProtocol. Therefore applications should use a singleton pattern as described in
TransportProtocol
's class documentation to ensure their protocol does not get disabled by garbage collection earlier than expected.The new protocol is registered in front of all earlier protocols, giving it higher priority than the built-in protocol definitions.
- Parameters:
proto
- the protocol definition. Must not be null.
-
unregister
Unregister a TransportProtocol instance.Unregistering a protocol usually isn't necessary, as protocols are held by weak references and will automatically clear when they are garbage collected by the JVM. Matching is handled by reference equality, so the exact reference given to
register(TransportProtocol)
must be used.- Parameters:
proto
- the exact object previously given to register.
-
getTransportProtocols
Obtain a copy of the registered protocols.- Returns:
- an immutable copy of the currently registered protocols.
-
open
public static Transport open(Repository local, String remote) throws NotSupportedException, URISyntaxException, TransportException Open a new transport instance to connect two repositories.This method assumes
Transport.Operation.FETCH
.- Parameters:
local
- existing local repository.remote
- location of the remote repository - may be URI or remote configuration name.- Returns:
- the new transport instance. Never null. In case of multiple URIs in remote configuration, only the first is chosen.
- Throws:
URISyntaxException
- the location is not a remote defined in the configuration file and is not a well-formed URL.NotSupportedException
- the protocol specified is not supported.TransportException
- the transport cannot open this URI.
-
open
public static Transport open(Repository local, String remote, Transport.Operation op) throws NotSupportedException, URISyntaxException, TransportException Open a new transport instance to connect two repositories.- Parameters:
local
- existing local repository.remote
- location of the remote repository - may be URI or remote configuration name.op
- planned use of the returned Transport; the URI may differ based on the type of connection desired.- Returns:
- the new transport instance. Never null. In case of multiple URIs in remote configuration, only the first is chosen.
- Throws:
URISyntaxException
- the location is not a remote defined in the configuration file and is not a well-formed URL.NotSupportedException
- the protocol specified is not supported.TransportException
- the transport cannot open this URI.
-
openAll
public static List<Transport> openAll(Repository local, String remote) throws NotSupportedException, URISyntaxException, TransportException Open new transport instances to connect two repositories.This method assumes
Transport.Operation.FETCH
.- Parameters:
local
- existing local repository.remote
- location of the remote repository - may be URI or remote configuration name.- Returns:
- the list of new transport instances for every URI in remote configuration.
- Throws:
URISyntaxException
- the location is not a remote defined in the configuration file and is not a well-formed URL.NotSupportedException
- the protocol specified is not supported.TransportException
- the transport cannot open this URI.
-
openAll
public static List<Transport> openAll(Repository local, String remote, Transport.Operation op) throws NotSupportedException, URISyntaxException, TransportException Open new transport instances to connect two repositories.- Parameters:
local
- existing local repository.remote
- location of the remote repository - may be URI or remote configuration name.op
- planned use of the returned Transport; the URI may differ based on the type of connection desired.- Returns:
- the list of new transport instances for every URI in remote configuration.
- Throws:
URISyntaxException
- the location is not a remote defined in the configuration file and is not a well-formed URL.NotSupportedException
- the protocol specified is not supported.TransportException
- the transport cannot open this URI.
-
open
public static Transport open(Repository local, RemoteConfig cfg) throws NotSupportedException, TransportException Open a new transport instance to connect two repositories.This method assumes
Transport.Operation.FETCH
.- Parameters:
local
- existing local repository.cfg
- configuration describing how to connect to the remote repository.- Returns:
- the new transport instance. Never null. In case of multiple URIs in remote configuration, only the first is chosen.
- Throws:
NotSupportedException
- the protocol specified is not supported.TransportException
- the transport cannot open this URI.IllegalArgumentException
- if provided remote configuration doesn't have any URI associated.
-
open
public static Transport open(Repository local, RemoteConfig cfg, Transport.Operation op) throws NotSupportedException, TransportException Open a new transport instance to connect two repositories.- Parameters:
local
- existing local repository.cfg
- configuration describing how to connect to the remote repository.op
- planned use of the returned Transport; the URI may differ based on the type of connection desired.- Returns:
- the new transport instance. Never null. In case of multiple URIs in remote configuration, only the first is chosen.
- Throws:
NotSupportedException
- the protocol specified is not supported.TransportException
- the transport cannot open this URI.IllegalArgumentException
- if provided remote configuration doesn't have any URI associated.
-
openAll
public static List<Transport> openAll(Repository local, RemoteConfig cfg) throws NotSupportedException, TransportException Open new transport instances to connect two repositories.This method assumes
Transport.Operation.FETCH
.- Parameters:
local
- existing local repository.cfg
- configuration describing how to connect to the remote repository.- Returns:
- the list of new transport instances for every URI in remote configuration.
- Throws:
NotSupportedException
- the protocol specified is not supported.TransportException
- the transport cannot open this URI.
-
openAll
public static List<Transport> openAll(Repository local, RemoteConfig cfg, Transport.Operation op) throws NotSupportedException, TransportException Open new transport instances to connect two repositories.- Parameters:
local
- existing local repository.cfg
- configuration describing how to connect to the remote repository.op
- planned use of the returned Transport; the URI may differ based on the type of connection desired.- Returns:
- the list of new transport instances for every URI in remote configuration.
- Throws:
NotSupportedException
- the protocol specified is not supported.TransportException
- the transport cannot open this URI.
-
getURIs
-
doesNotExist
-
open
public static Transport open(Repository local, URIish uri) throws NotSupportedException, TransportException Open a new transport instance to connect two repositories.- Parameters:
local
- existing local repository.uri
- location of the remote repository.- Returns:
- the new transport instance. Never null.
- Throws:
NotSupportedException
- the protocol specified is not supported.TransportException
- the transport cannot open this URI.
-
open
public static Transport open(Repository local, URIish uri, String remoteName) throws NotSupportedException, TransportException Open a new transport instance to connect two repositories.- Parameters:
local
- existing local repository.uri
- location of the remote repository.remoteName
- name of the remote, if the remote as configured inlocal
; otherwise null.- Returns:
- the new transport instance. Never null.
- Throws:
NotSupportedException
- the protocol specified is not supported.TransportException
- the transport cannot open this URI.
-
open
Open a new transport with no local repository.Note that the resulting transport instance can not be used for fetching or pushing, but only for reading remote refs.
- Parameters:
uri
- aURIish
object.- Returns:
- new Transport instance
- Throws:
NotSupportedException
TransportException
-
findRemoteRefUpdatesFor
public static Collection<RemoteRefUpdate> findRemoteRefUpdatesFor(Repository db, Collection<RefSpec> specs, Map<String, RefLeaseSpec> leases, Collection<RefSpec> fetchSpecs) throws IOExceptionConvert push remote refs update specification fromRefSpec
form toRemoteRefUpdate
. Conversion expands wildcards by matching source part to local refs. expectedOldObjectId in RemoteRefUpdate is set when specified in leases. Tracking branch is configured if RefSpec destination matches source of any fetch ref spec for this transport remote configuration.- Parameters:
db
- local database.specs
- collection of RefSpec to convert.leases
- map from ref to lease (containing expected old object id)fetchSpecs
- fetch specifications used for finding localtracking refs. May be null or empty collection.- Returns:
- collection of set up
RemoteRefUpdate
. - Throws:
IOException
- when problem occurred during conversion or specification set up: most probably, missing objects or refs.- Since:
- 4.7
-
findRemoteRefUpdatesFor
public static Collection<RemoteRefUpdate> findRemoteRefUpdatesFor(Repository db, Collection<RefSpec> specs, Collection<RefSpec> fetchSpecs) throws IOException Convert push remote refs update specification fromRefSpec
form toRemoteRefUpdate
. Conversion expands wildcards by matching source part to local refs. expectedOldObjectId in RemoteRefUpdate is always set as null. Tracking branch is configured if RefSpec destination matches source of any fetch ref spec for this transport remote configuration.- Parameters:
db
- local database.specs
- collection of RefSpec to convert.fetchSpecs
- fetch specifications used for finding localtracking refs. May be null or empty collection.- Returns:
- collection of set up
RemoteRefUpdate
. - Throws:
IOException
- when problem occurred during conversion or specification set up: most probably, missing objects or refs.
-
expandPushWildcardsFor
private static Collection<RefSpec> expandPushWildcardsFor(Repository db, Collection<RefSpec> specs) throws IOException - Throws:
IOException
-
findTrackingRefName
-
getURI
Get the URI this transport connects to.Each transport instance connects to at most one URI at any point in time.
- Returns:
- the URI describing the location of the remote repository.
-
getOptionUploadPack
Get the name of the remote executable providing upload-pack service.- Returns:
- typically "git-upload-pack".
-
setOptionUploadPack
Set the name of the remote executable providing upload-pack services.- Parameters:
where
- name of the executable.
-
getTagOpt
Get the description of how annotated tags should be treated during fetch.- Returns:
- option indicating the behavior of annotated tags in fetch.
-
setTagOpt
Set the description of how annotated tags should be treated on fetch.- Parameters:
option
- method to use when handling annotated tags.
-
isFetchThin
public boolean isFetchThin()Default setting is:DEFAULT_FETCH_THIN
- Returns:
- true if fetch should request thin-pack when possible; false otherwise
- See Also:
-
setFetchThin
public void setFetchThin(boolean fetchThin) Set the thin-pack preference for fetch operation. Default setting is:DEFAULT_FETCH_THIN
- Parameters:
fetchThin
- true when fetch should request thin-pack when possible; false when it shouldn't- See Also:
-
isCheckFetchedObjects
public boolean isCheckFetchedObjects()Whether fetch will verify if received objects are formatted correctly.- Returns:
- true if fetch will verify received objects are formatted correctly. Validating objects requires more CPU time on the client side of the connection.
-
setCheckFetchedObjects
public void setCheckFetchedObjects(boolean check) Configure if checking received objects is enabled- Parameters:
check
- true to enable checking received objects; false to assume all received objects are valid.- See Also:
-
getObjectChecker
Get configured object checker for received objects- Returns:
- configured object checker for received objects, or null.
- Since:
- 3.6
-
setObjectChecker
Set the object checker to verify each received object with- Parameters:
impl
- if non-null the object checking instance to verify each received object with; null to disable object checking.- Since:
- 3.6
-
getOptionReceivePack
Default setting is:RemoteConfig.DEFAULT_RECEIVE_PACK
- Returns:
- remote executable providing receive-pack service for pack transports.
- See Also:
-
setOptionReceivePack
Set remote executable providing receive-pack service for pack transports. Default setting is:RemoteConfig.DEFAULT_RECEIVE_PACK
- Parameters:
optionReceivePack
- remote executable, if null or empty default one is set;
-
isPushThin
public boolean isPushThin()Default setting is: false- Returns:
- true if push should produce thin-pack in pack transports
- See Also:
-
setPushThin
public void setPushThin(boolean pushThin) Set thin-pack preference for push operation. Default setting is: false- Parameters:
pushThin
- true when push should produce thin-pack in pack transports; false when it shouldn't- See Also:
-
isPushAtomic
public boolean isPushAtomic()Default setting is false.- Returns:
- true if push requires all-or-nothing atomic behavior.
- Since:
- 4.2
-
setPushAtomic
public void setPushAtomic(boolean atomic) Request atomic push (all references succeed, or none do).Server must also support atomic push. If the server does not support the feature the push will abort without making changes.
- Parameters:
atomic
- true when push should be an all-or-nothing operation.- Since:
- 4.2
- See Also:
-
isRemoveDeletedRefs
public boolean isRemoveDeletedRefs()Whether destination refs should be removed if they no longer exist at the source repository.- Returns:
- true if destination refs should be removed if they no longer exist at the source repository.
-
setRemoveDeletedRefs
public void setRemoveDeletedRefs(boolean remove) Set whether or not to remove refs which no longer exist in the source.If true, refs at the destination repository (local for fetch, remote for push) are deleted if they no longer exist on the source side (remote for fetch, local for push).
False by default, as this may cause data to become unreachable, and eventually be deleted on the next GC.
- Parameters:
remove
- true to remove refs that no longer exist.
-
getFilterBlobLimit
Deprecated.UsegetFilterSpec()
instead- Returns:
- the blob limit value set with
setFilterBlobLimit(long)
orsetFilterSpec(FilterSpec)
, or -1 if no blob limit value was set - Since:
- 5.0
-
setFilterBlobLimit
Deprecated.UsesetFilterSpec(FilterSpec)
instead- Parameters:
bytes
- exclude blobs of size greater than this- Since:
- 5.0
-
getFilterSpec
- Returns:
- the last filter spec set with
setFilterSpec(FilterSpec)
, orFilterSpec.NO_FILTER
if it was never invoked. - Since:
- 5.4
-
setFilterSpec
- Parameters:
filter
- a new filter to use for this transport- Since:
- 5.4
-
applyConfig
Apply provided remote configuration on this transport.- Parameters:
cfg
- configuration to apply on this transport.
-
isDryRun
public boolean isDryRun()Whether push operation should just check for possible result and not really update remote refs- Returns:
- true if push operation should just check for possible result and not really update remote refs, false otherwise - when push should act normally.
-
setDryRun
public void setDryRun(boolean dryRun) Set dry run option for push operation.- Parameters:
dryRun
- true if push operation should just check for possible result and not really update remote refs, false otherwise - when push should act normally.
-
getTimeout
public int getTimeout()Get timeout (in seconds) before aborting an IO operation.- Returns:
- timeout (in seconds) before aborting an IO operation.
-
setTimeout
public void setTimeout(int seconds) Set the timeout before willing to abort an IO call.- Parameters:
seconds
- number of seconds to wait (with no data transfer occurring) before aborting an IO read or write operation with this remote.
-
getPackConfig
Get the configuration used by the pack generator to make packs. IfsetPackConfig(PackConfig)
was previously given null a new PackConfig is created on demand by this method using the source repository's settings.- Returns:
- the pack configuration. Never null.
-
setPackConfig
Set the configuration used by the pack generator.- Parameters:
pc
- configuration controlling packing parameters. If null the source repository's settings will be used.
-
setCredentialsProvider
A credentials provider to assist with authentication connections..- Parameters:
credentialsProvider
- the credentials provider, or null if there is none
-
getCredentialsProvider
The configured credentials provider.- Returns:
- the credentials provider, or null if no credentials provider is associated with this transport.
-
getPushOptions
Get the option strings associated with the push operation- Returns:
- the option strings associated with the push operation
- Since:
- 4.5
-
setPushOptions
Sets the option strings associated with the push operation.- Parameters:
pushOptions
- null if push options are unsupported- Since:
- 4.5
-
fetch
public FetchResult fetch(ProgressMonitor monitor, Collection<RefSpec> toFetch) throws NotSupportedException, TransportException Fetch objects and refs from the remote repository to the local one.This is a utility function providing standard fetch behavior. Local tracking refs associated with the remote repository are automatically updated if this transport was created from a
RemoteConfig
with fetch RefSpecs defined.- Parameters:
monitor
- progress monitor to inform the user about our processing activity. Must not be null. UseNullProgressMonitor
if progress updates are not interesting or necessary.toFetch
- specification of refs to fetch locally. May be null or the empty collection to use the specifications from the RemoteConfig. Source for each RefSpec can't be null.- Returns:
- information describing the tracking refs updated.
- Throws:
NotSupportedException
- this transport implementation does not support fetching objects.TransportException
- the remote connection could not be established or object copying (if necessary) failed or update specification was incorrect.- Since:
- 5.11
-
fetch
public FetchResult fetch(ProgressMonitor monitor, Collection<RefSpec> toFetch, String branch) throws NotSupportedException, TransportException Fetch objects and refs from the remote repository to the local one.This is a utility function providing standard fetch behavior. Local tracking refs associated with the remote repository are automatically updated if this transport was created from a
RemoteConfig
with fetch RefSpecs defined.- Parameters:
monitor
- progress monitor to inform the user about our processing activity. Must not be null. UseNullProgressMonitor
if progress updates are not interesting or necessary.toFetch
- specification of refs to fetch locally. May be null or the empty collection to use the specifications from the RemoteConfig. Source for each RefSpec can't be null.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 passingnull
orHEAD
.- Returns:
- information describing the tracking refs updated.
- Throws:
NotSupportedException
- this transport implementation does not support fetching objects.TransportException
- the remote connection could not be established or object copying (if necessary) failed or update specification was incorrect.- Since:
- 5.11
-
push
public PushResult push(ProgressMonitor monitor, Collection<RemoteRefUpdate> toPush, OutputStream out) throws NotSupportedException, TransportException Push objects and refs from the local repository to the remote one.This is a utility function providing standard push behavior. It updates remote refs and send there necessary objects according to remote ref update specification. After successful remote ref update, associated locally stored tracking branch is updated if set up accordingly. Detailed operation result is provided after execution.
For setting up remote ref update specification from ref spec, see helper method
findRemoteRefUpdatesFor(Collection)
, predefined refspecs (REFSPEC_TAGS
,REFSPEC_PUSH_ALL
) or consider using directlyRemoteRefUpdate
for more possibilities.When
isDryRun()
is true, result of this operation is just estimation of real operation result, no real action is performed.- Parameters:
monitor
- progress monitor to inform the user about our processing activity. Must not be null. UseNullProgressMonitor
if progress updates are not interesting or necessary.toPush
- specification of refs to push. May be null or the empty collection to use the specifications from the RemoteConfig converted byfindRemoteRefUpdatesFor(Collection)
. No more than 1 RemoteRefUpdate with the same remoteName is allowed. These objects are modified during this call.out
- output stream to write messages to- Returns:
- information about results of remote refs updates, tracking refs updates and refs advertised by remote repository.
- Throws:
NotSupportedException
- this transport implementation does not support pushing objects.TransportException
- the remote connection could not be established or object copying (if necessary) failed at I/O or protocol level or update specification was incorrect.- Since:
- 3.0
- See Also:
-
push
public PushResult push(ProgressMonitor monitor, Collection<RemoteRefUpdate> toPush) throws NotSupportedException, TransportException Push objects and refs from the local repository to the remote one.This is a utility function providing standard push behavior. It updates remote refs and sends necessary objects according to remote ref update specification. After successful remote ref update, associated locally stored tracking branch is updated if set up accordingly. Detailed operation result is provided after execution.
For setting up remote ref update specification from ref spec, see helper method
findRemoteRefUpdatesFor(Collection)
, predefined refspecs (REFSPEC_TAGS
,REFSPEC_PUSH_ALL
) or consider using directlyRemoteRefUpdate
for more possibilities.When
isDryRun()
is true, result of this operation is just estimation of real operation result, no real action is performed.- Parameters:
monitor
- progress monitor to inform the user about our processing activity. Must not be null. UseNullProgressMonitor
if progress updates are not interesting or necessary.toPush
- specification of refs to push. May be null or the empty collection to use the specifications from the RemoteConfig converted byfindRemoteRefUpdatesFor(Collection)
. No more than 1 RemoteRefUpdate with the same remoteName is allowed. These objects are modified during this call.- Returns:
- information about results of remote refs updates, tracking refs updates and refs advertised by remote repository.
- Throws:
NotSupportedException
- this transport implementation does not support pushing objects.TransportException
- the remote connection could not be established or object copying (if necessary) failed at I/O or protocol level or update specification was incorrect.- See Also:
-
findRemoteRefUpdatesFor
public Collection<RemoteRefUpdate> findRemoteRefUpdatesFor(Collection<RefSpec> specs) throws IOException Convert push remote refs update specification fromRefSpec
form toRemoteRefUpdate
. Conversion expands wildcards by matching source part to local refs. expectedOldObjectId in RemoteRefUpdate is always set as null. Tracking branch is configured if RefSpec destination matches source of any fetch ref spec for this transport remote configuration.Conversion is performed for context of this transport (database, fetch specifications).
- Parameters:
specs
- collection of RefSpec to convert.- Returns:
- collection of set up
RemoteRefUpdate
. - Throws:
IOException
- when problem occurred during conversion or specification set up: most probably, missing objects or refs.
-
findRemoteRefUpdatesFor
public Collection<RemoteRefUpdate> findRemoteRefUpdatesFor(Collection<RefSpec> specs, Map<String, RefLeaseSpec> leases) throws IOExceptionConvert push remote refs update specification fromRefSpec
form toRemoteRefUpdate
. Conversion expands wildcards by matching source part to local refs. expectedOldObjectId in RemoteRefUpdate is set according to leases. Tracking branch is configured if RefSpec destination matches source of any fetch ref spec for this transport remote configuration.Conversion is performed for context of this transport (database, fetch specifications).
- Parameters:
specs
- collection of RefSpec to convert.leases
- map from ref to lease (containing expected old object id)- Returns:
- collection of set up
RemoteRefUpdate
. - Throws:
IOException
- when problem occurred during conversion or specification set up: most probably, missing objects or refs.- Since:
- 4.7
-
openFetch
Begins a new connection for fetching from the remote repository.If the transport has no local repository, the fetch connection can only be used for reading remote refs.
- Returns:
- a fresh connection to fetch from the remote repository.
- Throws:
NotSupportedException
- the implementation does not support fetching.TransportException
- the remote connection could not be established.
-
openFetch
public FetchConnection openFetch(Collection<RefSpec> refSpecs, String... additionalPatterns) throws NotSupportedException, TransportException Begins a new connection for fetching from the remote repository.If the transport has no local repository, the fetch connection can only be used for reading remote refs.
If the server supports git protocol V2, the
RefSpec
s and the additional patterns, if any, are used to restrict the server's ref advertisement to matching refs only.Transports that want to support git protocol V2 must override this; the default implementation ignores its arguments and calls
openFetch()
.- Parameters:
refSpecs
- that will be fetched viaFetchConnection.fetch(ProgressMonitor, Collection, java.util.Set, OutputStream)
lateradditionalPatterns
- that will be set as ref prefixes if the server supports git protocol V2;null
values are ignored- Returns:
- a fresh connection to fetch from the remote repository.
- Throws:
NotSupportedException
- the implementation does not support fetching.TransportException
- the remote connection could not be established.- Since:
- 5.11
-
openPush
Begins a new connection for pushing into the remote repository.- Returns:
- a fresh connection to push into the remote repository.
- Throws:
NotSupportedException
- the implementation does not support pushing.TransportException
- the remote connection could not be established
-
close
public abstract void close()Close any resources used by this transport.
If the remote repository is contacted by a network socket this method must close that network socket, disconnecting the two peers. If the remote repository is actually local (same system) this method must close any open file handles used to read the "remote" repository.
AutoClosable.close()
declares that it throwsException
. Implementers shouldn't throw checked exceptions. This override narrows the signature to prevent them from doing so.- Specified by:
close
in interfaceAutoCloseable
-
getFilterSpec()
instead