Class CloneCommand

All Implemented Interfaces:
Callable<Git>

public class CloneCommand extends TransportCommand<CloneCommand,Git>
Clone a repository into a new working directory
See Also:
  • Constructor Details

    • CloneCommand

      public CloneCommand()
      Create clone command with no repository set
  • Method Details

    • 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 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.

      Specified by:
      call in interface Callable<Git>
      Specified by:
      call in class GitCommand<Git>
      Throws:
      GitAPIException
      InvalidRemoteException
      TransportException
    • setURI

      public CloneCommand setURI(String uri)
      Set the URI to clone from
      Parameters:
      uri - the URI to clone from, or null to unset the URI. The URI must be set before call() is called.
      Returns:
      this instance
    • setDirectory

      public CloneCommand setDirectory(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, or null 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

      public CloneCommand setGitDir(File gitDir)
      Set the repository meta directory (.git)
      Parameters:
      gitDir - the repository meta directory, or null 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

      public CloneCommand setBare(boolean bare) throws IllegalStateException
      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

      public CloneCommand setFs(FS fs)
      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

      public CloneCommand setRemote(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 of Constants.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

      public CloneCommand setBranch(String branch)
      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 passing null or HEAD.
      Returns:
      this instance
    • setProgressMonitor

      public CloneCommand setProgressMonitor(ProgressMonitor monitor)
      The progress monitor associated with the clone operation. By default, this is set to NullProgressMonitor
      Parameters:
      monitor - a ProgressMonitor
      Returns:
      this
      See Also:
    • setCloneAllBranches

      public CloneCommand setCloneAllBranches(boolean cloneAllBranches)
      Set whether all branches have to be fetched.

      If false, use setBranchesToClone(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

      public CloneCommand setMirror(boolean mirror)
      Set up a mirror of the source repository. This implies that a bare repository will be created. Compared to setBare(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

      public CloneCommand setCloneSubmodules(boolean cloneSubmodules)
      Set whether to clone submodules
      Parameters:
      cloneSubmodules - true to initialize and update submodules. Ignored when setBare(boolean) is set to true.
      Returns:
      this
    • setBranchesToClone

      public CloneCommand setBranchesToClone(Collection<String> branchesToClone)
      Set the branches or tags to clone.

      This is ignored if setCloneAllBranches(true) or setMirror(true) is used. If branchesToClone is null 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 or refs/tags/v1.0.0).
      Returns:
      this
    • setTagOption

      public CloneCommand setTagOption(TagOpt tagOption)
      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

      public CloneCommand 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

      public CloneCommand setNoCheckout(boolean noCheckout)
      Set whether to skip checking out a branch
      Parameters:
      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.
      Returns:
      this
    • setCallback

      public CloneCommand setCallback(CloneCommand.Callback callback)
      Register a progress callback.
      Parameters:
      callback - the callback
      Returns:
      this
      Since:
      4.8
    • setDepth

      public CloneCommand setDepth(int depth)
      Creates a shallow clone with a history truncated to the specified number of commits.
      Parameters:
      depth - the depth
      Returns:
      this
      Since:
      6.3
    • setShallowSince

      public CloneCommand setShallowSince(@NonNull OffsetDateTime shallowSince)
      Creates a shallow clone with a history after the specified time.
      Parameters:
      shallowSince - the timestammp; must not be null
      Returns:
      this
      Since:
      6.3
    • setShallowSince

      public CloneCommand setShallowSince(@NonNull Instant shallowSince)
      Creates a shallow clone with a history after the specified time.
      Parameters:
      shallowSince - the timestammp; must not be null
      Returns:
      this
      Since:
      6.3
    • addShallowExclude

      public CloneCommand addShallowExclude(@NonNull String shallowExclude)
      Creates a shallow clone with a history, excluding commits reachable from a specified remote branch or tag.
      Parameters:
      shallowExclude - the ref or commit; must not be null
      Returns:
      this
      Since:
      6.3
    • addShallowExclude

      public CloneCommand addShallowExclude(@NonNull ObjectId shallowExclude)
      Creates a shallow clone with a history, excluding commits reachable from a specified remote branch or tag.
      Parameters:
      shallowExclude - the commit; must not be null
      Returns:
      this
      Since:
      6.3