Package org.eclipse.jgit.api
Class CloneCommand
Clone a repository into a new working directory
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interface
Callback for status of clone operation.private static enum
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate boolean
private String
private Collection
<String> private CloneCommand.Callback
private boolean
private boolean
private File
private boolean
private CloneCommand.FETCH_TYPE
private FS
private File
private boolean
private boolean
private ProgressMonitor
private boolean
private String
private TagOpt
private String
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 -
Method Summary
Modifier and TypeMethodDescriptionprivate void
addMergeConfig
(Repository clonedRepo, Ref head) calculateRefSpecs
(CloneCommand.FETCH_TYPE type, String remoteName) call()
private void
checkout
(Repository clonedRepo, FetchResult result) private void
cleanup()
private void
cloneSubmodules
(Repository clonedRepo) private void
deleteChildren
(File file) private FetchResult
fetch
(Repository clonedRepo, URIish u) private Ref
findBranchToCheckout
(FetchResult result) (package private) File
Get the git directory.private Repository
init()
private static boolean
isNonEmptyDirectory
(File dir) private RevCommit
parseCommit
(Repository clonedRepo, Ref ref) setBare
(boolean bare) Set whether the cloned repository shall be bareSet the initial branchsetBranchesToClone
(Collection<String> branchesToClone) Set the branches or tags to clone.setCallback
(CloneCommand.Callback callback) Register a progress callback.setCloneAllBranches
(boolean cloneAllBranches) Set whether all branches have to be fetched.setCloneSubmodules
(boolean cloneSubmodules) Set whether to clone submodulessetDirectory
(File directory) The optional directory associated with the clone operation.private void
Set the file system abstraction to be used for repositories created by this command.Set the repository meta directory (.git)setMirror
(boolean mirror) Set up a mirror of the source repository.setNoCheckout
(boolean noCheckout) Set whether to skip checking out a branchSet the --no-tags option.setProgressMonitor
(ProgressMonitor monitor) The progress monitor associated with the clone operation.The remote name used to keep track of the upstream repository for the clone operation.setTagOption
(TagOpt tagOption) Set the tag option used for the remote configuration explicitly.Set the URI to clone fromprivate static void
validateDirs
(File directory, File gitDir, boolean bare) (package private) void
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
-
Field Details
-
uri
-
directory
-
gitDir
-
bare
private boolean bare -
fs
-
remote
-
branch
-
monitor
-
cloneAllBranches
private boolean cloneAllBranches -
mirror
private boolean mirror -
cloneSubmodules
private boolean cloneSubmodules -
noCheckout
private boolean noCheckout -
branchesToClone
-
callback
-
directoryExistsInitially
private boolean directoryExistsInitially -
gitDirExistsInitially
private boolean gitDirExistsInitially -
fetchType
-
tagOption
-
-
Constructor Details
-
CloneCommand
public CloneCommand()Create clone command with no repository set
-
-
Method Details
-
getDirectory
Get the git directory. This is primarily used for tests.- Returns:
- the git directory
-
call
Execute the command
Executes the
Clone
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 interfaceCallable<Git>
- Specified by:
call
in classGitCommand<Git>
- Throws:
GitAPIException
InvalidRemoteException
TransportException
-
setFetchType
private void setFetchType() -
isNonEmptyDirectory
-
verifyDirectories
-
init
- Throws:
GitAPIException
-
fetch
private FetchResult fetch(Repository clonedRepo, URIish u) throws URISyntaxException, TransportException, IOException, GitAPIException -
calculateRefSpecs
-
checkout
private void checkout(Repository clonedRepo, FetchResult result) throws MissingObjectException, IncorrectObjectTypeException, IOException, GitAPIException -
cloneSubmodules
- Throws:
IOException
GitAPIException
-
findBranchToCheckout
-
addMergeConfig
- Throws:
IOException
-
parseCommit
private RevCommit parseCommit(Repository clonedRepo, Ref ref) throws MissingObjectException, IncorrectObjectTypeException, IOException -
setURI
Set the URI to clone from- Parameters:
uri
- the URI to clone from, ornull
to unset the URI. The URI must be set beforecall()
is called.- Returns:
- this instance
-
setDirectory
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, ornull
if the directory name should be taken from the source uri- Returns:
- this instance
- Throws:
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:
-
setGitDir
Set the repository meta directory (.git)- Parameters:
gitDir
- the repository meta directory, ornull
to choose one automatically at clone time- Returns:
- this instance
- Throws:
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
Set whether the cloned repository shall be bare- Parameters:
bare
- whether the cloned repository is bare or not- Returns:
- this instance
- Throws:
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
-
setFs
Set the file system abstraction to be used for repositories created by this command.- Parameters:
fs
- the abstraction.- Returns:
this
(for chaining calls).- Since:
- 4.10
-
setRemote
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.null
means to use DEFAULT_REMOTE_NAME.- Returns:
- this instance
- See Also:
-
setBranch
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 passingnull
orHEAD
.- Returns:
- this instance
-
setProgressMonitor
The progress monitor associated with the clone operation. By default, this is set toNullProgressMonitor
- Parameters:
monitor
- aProgressMonitor
- Returns:
this
- See Also:
-
setCloneAllBranches
Set whether all branches have to be fetched.If
false
, usesetBranchesToClone(Collection)
to define what will be cloned. If neither are set, all branches will be cloned.- Parameters:
cloneAllBranches
-true
when all branches have to be fetched (indicates wildcard in created fetch refspec),false
otherwise.- Returns:
this
-
setMirror
Set up a mirror of the source repository. This implies that a bare repository will be created. Compared tosetBare(boolean)
,#setMirror
not only maps local branches of the source to local branches of the target, it maps all refs (including remote-tracking branches, notes etc.) and sets up a refspec configuration such that all these refs are overwritten by a git remote update in the target repository.- Parameters:
mirror
- whether to mirror all refs from the source repository- Returns:
this
- Since:
- 5.6
-
setCloneSubmodules
Set whether to clone submodules- Parameters:
cloneSubmodules
- true to initialize and update submodules. Ignored whensetBare(boolean)
is set to true.- Returns:
this
-
setBranchesToClone
Set the branches or tags to clone.This is ignored if
setCloneAllBranches(true)
orsetMirror(true)
is used. IfbranchesToClone
isnull
or empty, it's also ignored.- Parameters:
branchesToClone
- collection of branches to clone. Must be specified as full ref names (e.g.refs/heads/master
orrefs/tags/v1.0.0
).- Returns:
this
-
setTagOption
Set the tag option used for the remote configuration explicitly.- Parameters:
tagOption
- tag option to be used for the remote config- Returns:
this
- Since:
- 5.8
-
setNoTags
Set the --no-tags option. Tags are not cloned now and the remote configuration is initialized with the --no-tags option as well.- Returns:
this
- Since:
- 5.8
-
setNoCheckout
Set whether to skip checking out a branch- 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
-
setCallback
Register a progress callback.- Parameters:
callback
- the callback- Returns:
this
- Since:
- 4.8
-
validateDirs
private static void validateDirs(File directory, File gitDir, boolean bare) throws IllegalStateException - Throws:
IllegalStateException
-
cleanup
private void cleanup() -
deleteChildren
- Throws:
IOException
-