public class CloneCommand extends TransportCommand<CloneCommand,Git>
| Modifier and Type | Class and Description |
|---|---|
static interface |
CloneCommand.Callback
Callback for status of clone operation.
|
| Modifier and Type | Field and Description |
|---|---|
private boolean |
bare |
private java.lang.String |
branch |
private java.util.Collection<java.lang.String> |
branchesToClone |
private CloneCommand.Callback |
callback |
private boolean |
cloneAllBranches |
private boolean |
cloneSubmodules |
private java.io.File |
directory |
private boolean |
directoryExistsInitially |
private FS |
fs |
private java.io.File |
gitDir |
private boolean |
gitDirExistsInitially |
private ProgressMonitor |
monitor |
private boolean |
noCheckout |
private java.lang.String |
remote |
private java.lang.String |
uri |
credentialsProvider, timeout, transportConfigCallbackrepo| Constructor and Description |
|---|
CloneCommand()
Create clone command with no repository set
|
| Modifier and Type | Method and Description |
|---|---|
private void |
addMergeConfig(Repository clonedRepo,
Ref head) |
private java.util.List<RefSpec> |
calculateRefSpecs(java.lang.String dst) |
Git |
call() |
private void |
checkout(Repository clonedRepo,
FetchResult result) |
private void |
cleanup() |
private void |
cloneSubmodules(Repository clonedRepo) |
private void |
deleteChildren(java.io.File file) |
private FetchResult |
fetch(Repository clonedRepo,
URIish u) |
private Ref |
findBranchToCheckout(FetchResult result) |
(package private) java.io.File |
getDirectory()
Get the git directory.
|
private Repository |
init() |
private static boolean |
isNonEmptyDirectory(java.io.File dir) |
private RevCommit |
parseCommit(Repository clonedRepo,
Ref ref) |
CloneCommand |
setBare(boolean bare)
Set whether the cloned repository shall be bare
|
CloneCommand |
setBranch(java.lang.String branch)
Set the initial branch
|
CloneCommand |
setBranchesToClone(java.util.Collection<java.lang.String> branchesToClone)
Set branches to clone
|
CloneCommand |
setCallback(CloneCommand.Callback callback)
Register a progress callback.
|
CloneCommand |
setCloneAllBranches(boolean cloneAllBranches)
Set whether all branches have to be fetched
|
CloneCommand |
setCloneSubmodules(boolean cloneSubmodules)
Set whether to clone submodules
|
CloneCommand |
setDirectory(java.io.File directory)
The optional directory associated with the clone operation.
|
CloneCommand |
setFs(FS fs)
Set the file system abstraction to be used for repositories created by
this command.
|
CloneCommand |
setGitDir(java.io.File gitDir)
Set the repository meta directory (.git)
|
CloneCommand |
setNoCheckout(boolean noCheckout)
Set whether to skip checking out a branch
|
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)
Set the URI to clone from
|
private static void |
validateDirs(java.io.File directory,
java.io.File gitDir,
boolean bare) |
(package private) void |
verifyDirectories(URIish u) |
configure, configure, self, setCredentialsProvider, setTimeout, setTransportConfigCallbackcheckCallable, getRepository, setCallableprivate java.lang.String uri
private java.io.File directory
private java.io.File gitDir
private boolean bare
private FS fs
private java.lang.String remote
private java.lang.String branch
private ProgressMonitor monitor
private boolean cloneAllBranches
private boolean cloneSubmodules
private boolean noCheckout
private java.util.Collection<java.lang.String> branchesToClone
private CloneCommand.Callback callback
private boolean directoryExistsInitially
private boolean gitDirExistsInitially
@Nullable java.io.File getDirectory()
public Git call() throws GitAPIException, InvalidRemoteException, TransportException
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 underlying Repository
instance. It is recommended to call this method as soon as you don't need
a reference to this Git instance and the underlying
Repository instance anymore.
call in interface java.util.concurrent.Callable<Git>call in class GitCommand<Git>GitAPIExceptionInvalidRemoteExceptionTransportExceptionprivate static boolean isNonEmptyDirectory(java.io.File dir)
void verifyDirectories(URIish u)
private Repository init() throws GitAPIException
GitAPIExceptionprivate FetchResult fetch(Repository clonedRepo, URIish u) throws java.net.URISyntaxException, TransportException, java.io.IOException, GitAPIException
java.net.URISyntaxExceptionTransportExceptionjava.io.IOExceptionGitAPIExceptionprivate java.util.List<RefSpec> calculateRefSpecs(java.lang.String dst)
private void checkout(Repository clonedRepo, FetchResult result) throws MissingObjectException, IncorrectObjectTypeException, java.io.IOException, GitAPIException
MissingObjectExceptionIncorrectObjectTypeExceptionjava.io.IOExceptionGitAPIExceptionprivate void cloneSubmodules(Repository clonedRepo) throws java.io.IOException, GitAPIException
java.io.IOExceptionGitAPIExceptionprivate Ref findBranchToCheckout(FetchResult result)
private void addMergeConfig(Repository clonedRepo, Ref head) throws java.io.IOException
java.io.IOExceptionprivate RevCommit parseCommit(Repository clonedRepo, Ref ref) throws MissingObjectException, IncorrectObjectTypeException, java.io.IOException
MissingObjectExceptionIncorrectObjectTypeExceptionjava.io.IOExceptionpublic CloneCommand setURI(java.lang.String uri)
uri - the URI to clone from, or null to unset the URI. The
URI must be set before call() is called.public CloneCommand setDirectory(java.io.File directory)
directory - the directory to clone to, or null if the directory
name should be taken from the source urijava.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 specifiedURIish.getHumanishName()public CloneCommand setGitDir(java.io.File gitDir)
gitDir - the repository meta directory, or null to choose one
automatically at clone timejava.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 specifiedpublic CloneCommand setBare(boolean bare) throws java.lang.IllegalStateException
bare - whether the cloned repository is bare or notjava.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 specifiedpublic CloneCommand setFs(FS fs)
fs - the abstraction.this (for chaining calls).public CloneCommand setRemote(java.lang.String remote)
Constants.DEFAULT_REMOTE_NAME will be used.remote - name that keeps track of the upstream repository.
null means to use DEFAULT_REMOTE_NAME.Constants.DEFAULT_REMOTE_NAMEpublic CloneCommand setBranch(java.lang.String branch)
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 passing null or HEAD.public CloneCommand setProgressMonitor(ProgressMonitor monitor)
NullProgressMonitormonitor - a ProgressMonitorthisNullProgressMonitorpublic CloneCommand setCloneAllBranches(boolean cloneAllBranches)
cloneAllBranches - true when all branches have to be fetched (indicates wildcard
in created fetch refspec), false otherwise.thispublic CloneCommand setCloneSubmodules(boolean cloneSubmodules)
cloneSubmodules - true to initialize and update submodules. Ignored when
setBare(boolean) is set to true.thispublic CloneCommand setBranchesToClone(java.util.Collection<java.lang.String> branchesToClone)
branchesToClone - collection of branches to clone. Ignored when allSelected is
true. Must be specified as full ref names (e.g.
refs/heads/master).thispublic CloneCommand setNoCheckout(boolean noCheckout)
noCheckout - if set to true 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.thispublic CloneCommand setCallback(CloneCommand.Callback callback)
callback - the callbackthisprivate static void validateDirs(java.io.File directory,
java.io.File gitDir,
boolean bare)
throws java.lang.IllegalStateException
java.lang.IllegalStateExceptionprivate void cleanup()
private void deleteChildren(java.io.File file)
throws java.io.IOException
java.io.IOException