Class InitCommand

java.lang.Object
org.eclipse.jgit.api.InitCommand
All Implemented Interfaces:
Callable<Git>

public class InitCommand extends Object implements Callable<Git>
Create an empty git repository or reinitalize an existing one
See Also:
  • Field Details

    • directory

      private File directory
    • gitDir

      private File gitDir
    • bare

      private boolean bare
    • fs

      private FS fs
    • initialBranch

      private String initialBranch
  • Constructor Details

    • InitCommand

      public InitCommand()
  • Method Details

    • call

      public Git call() throws GitAPIException

      Executes the Init command.

      Specified by:
      call in interface Callable<Git>
      Returns:
      a Git instance that owns the Repository that it wraps.
      Throws:
      GitAPIException
    • setDirectory

      public InitCommand setDirectory(File directory) throws IllegalStateException
      The optional directory associated with the init operation. If no directory is set, we'll use the current directory
      Parameters:
      directory - the directory to init to
      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
    • setGitDir

      public InitCommand setGitDir(File gitDir) throws IllegalStateException
      Set the repository meta directory (.git)
      Parameters:
      gitDir - the repository meta directory
      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
    • validateDirs

      private static void validateDirs(File directory, File gitDir, boolean bare) throws IllegalStateException
      Throws:
      IllegalStateException
    • setBare

      public InitCommand setBare(boolean bare)
      Set whether the repository is bare or not
      Parameters:
      bare - whether the 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 InitCommand 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
    • setInitialBranch

      public InitCommand setInitialBranch(String branch) throws InvalidRefNameException
      Set the initial branch of the new repository. If not specified (null or empty), fall back to the default name (currently master).
      Parameters:
      branch - initial branch name of the new repository
      Returns:
      this
      Throws:
      InvalidRefNameException - if the branch name is not valid
      Since:
      5.11