Package org.eclipse.jgit.api
Class CloneCommand
- java.lang.Object
-
- org.eclipse.jgit.api.GitCommand<T>
-
- org.eclipse.jgit.api.TransportCommand<CloneCommand,Git>
-
- org.eclipse.jgit.api.CloneCommand
-
- All Implemented Interfaces:
java.util.concurrent.Callable<Git>
public class CloneCommand extends TransportCommand<CloneCommand,Git>
Clone a repository into a new working directory- See Also:
- Git documentation about Clone
-
-
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 Constructor Description CloneCommand()
Create clone command with no repository set
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Git
call()
Executes theClone
command.CloneCommand
setBare(boolean bare)
CloneCommand
setBranch(java.lang.String branch)
CloneCommand
setBranchesToClone(java.util.Collection<java.lang.String> branchesToClone)
CloneCommand
setCloneAllBranches(boolean cloneAllBranches)
CloneCommand
setCloneSubmodules(boolean cloneSubmodules)
CloneCommand
setDirectory(java.io.File directory)
The optional directory associated with the clone operation.CloneCommand
setGitDir(java.io.File gitDir)
CloneCommand
setNoCheckout(boolean noCheckout)
CloneCommand
setProgressMonitor(ProgressMonitor monitor)
The progress monitor associated with the clone operation.CloneCommand
setRemote(java.lang.String remote)
The remote name used to keep track of the upstream repository for the clone operation.CloneCommand
setURI(java.lang.String uri)
-
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
-
-
-
-
Method Detail
-
call
public Git call() throws GitAPIException, InvalidRemoteException, TransportException
Executes theClone
command. The Git instance returned by this command needs to be closed by the caller to free resources held by the underlyingRepository
instance. It is recommended to call this method as soon as you don't need a reference to thisGit
instance and the underlyingRepository
instance anymore.- Specified by:
call
in interfacejava.util.concurrent.Callable<Git>
- Specified by:
call
in classGitCommand<Git>
- Returns:
- the newly created
Git
object with associated repository - Throws:
InvalidRemoteException
TransportException
GitAPIException
-
setURI
public CloneCommand setURI(java.lang.String uri)
- Parameters:
uri
- the uri to clone from- Returns:
- this instance
-
setDirectory
public CloneCommand setDirectory(java.io.File directory)
The optional directory associated with the clone operation. If the directory isn't set, a name associated with the source uri will be used.- Parameters:
directory
- the directory to clone to- Returns:
- this instance
- Throws:
java.lang.IllegalStateException
- if the combination of directory, gitDir and bare is illegal. E.g. if for a non-bare repository directory and gitDir point to the same directory of if for a bare repository both directory and gitDir are specified- See Also:
URIish.getHumanishName()
-
setGitDir
public CloneCommand setGitDir(java.io.File gitDir)
- Parameters:
gitDir
- the repository meta directory- Returns:
- this instance
- Throws:
java.lang.IllegalStateException
- if the combination of directory, gitDir and bare is illegal. E.g. if for a non-bare repository directory and gitDir point to the same directory of if for a bare repository both directory and gitDir are specified- Since:
- 3.6
-
setBare
public CloneCommand setBare(boolean bare) throws java.lang.IllegalStateException
- Parameters:
bare
- whether the cloned repository is bare or not- Returns:
- this instance
- Throws:
java.lang.IllegalStateException
- if the combination of directory, gitDir and bare is illegal. E.g. if for a non-bare repository directory and gitDir point to the same directory of if for a bare repository both directory and gitDir are specified
-
setRemote
public CloneCommand setRemote(java.lang.String remote)
The remote name used to keep track of the upstream repository for the clone operation. If no remote name is set, the default value ofConstants.DEFAULT_REMOTE_NAME
will be used.- Parameters:
remote
- name that keeps track of the upstream repository- Returns:
- this instance
- See Also:
Constants.DEFAULT_REMOTE_NAME
-
setBranch
public CloneCommand setBranch(java.lang.String 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
).- Returns:
- this instance
-
setProgressMonitor
public CloneCommand setProgressMonitor(ProgressMonitor monitor)
The progress monitor associated with the clone operation. By default, this is set toNullProgressMonitor
- Parameters:
monitor
-- Returns:
this
- See Also:
NullProgressMonitor
-
setCloneAllBranches
public CloneCommand setCloneAllBranches(boolean cloneAllBranches)
- Parameters:
cloneAllBranches
- true when all branches have to be fetched (indicates wildcard in created fetch refspec), false otherwise.- Returns:
this
-
setCloneSubmodules
public CloneCommand setCloneSubmodules(boolean cloneSubmodules)
- Parameters:
cloneSubmodules
- true to initialize and update submodules. Ignored whensetBare(boolean)
is set to true.- Returns:
this
-
setBranchesToClone
public CloneCommand setBranchesToClone(java.util.Collection<java.lang.String> branchesToClone)
- Parameters:
branchesToClone
- collection of branches to clone. Ignored when allSelected is true. Must be specified as full ref names (e.g.refs/heads/master
).- Returns:
this
-
setNoCheckout
public CloneCommand setNoCheckout(boolean noCheckout)
- Parameters:
noCheckout
- if set totrue
no branch will be checked out after the clone. This enhances performance of the clone command when there is no need for a checked out branch.- Returns:
this
-
-