Top Description Fields Constructors Methods
org.eclipse.jgit.api

public Class InitCommand

extends Object
implements Callable<Git>
Class Inheritance
All Implemented Interfaces
java.util.concurrent.Callable
Imports
java.io.File, .IOException, java.text.MessageFormat, java.util.concurrent.Callable, org.eclipse.jgit.api.errors.GitAPIException, .InvalidRefNameException, .JGitInternalException, org.eclipse.jgit.errors.ConfigInvalidException, org.eclipse.jgit.internal.JGitText, org.eclipse.jgit.internal.storage.file.FileRepository, org.eclipse.jgit.lib.ConfigConstants, .Constants, .Repository, .RepositoryBuilder, org.eclipse.jgit.util.FS, .StringUtils, .SystemReader

Create an empty git repository or reinitalize an existing one
See Also
Git documentation about init

Field Summary

Modifier and TypeField and Description
private boolean
private File
private FS
private File
private String
private boolean

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public Git

Returns:

a Git instance that owns the Repository that it wraps.
call
()

Implements java.util.concurrent.Callable.call.

Computes a result, or throws an exception if unable to do so.

public InitCommand

Returns:

this instance
setBare
(boolean
whether the repository is bare or not
bare
)

Set whether the repository is bare or not

public InitCommand

Returns:

this instance
setDirectory
(File
the directory to init to
directory
)

The optional directory associated with the init operation.

public InitCommand

Returns:

this (for chaining calls).
setFs
(FS
the abstraction.
fs
)

Set the file system abstraction to be used for repositories created by this command.

public InitCommand

Returns:

this instance
setGitDir
(File
the repository meta directory
gitDir
)

Set the repository meta directory (.git)

public InitCommand

Returns:

this
setInitialBranch
(String
initial branch name of the new repository
branch
)

Set the initial branch of the new repository.

public InitCommand

Returns:

this
setRelativeDirs
(boolean
if true, use relative paths for GIT_DIR and GIT_WORK_TREE
relativePaths
)

* Set whether the repository shall use relative paths for GIT_DIR and GIT_WORK_TREE

private static void
validateDirs(File directory, File gitDir, boolean bare)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

bareback to summary
private boolean bare
directoryback to summary
private File directory
fsback to summary
private FS fs
gitDirback to summary
private File gitDir
initialBranchback to summary
private String initialBranch
relativePathsback to summary
private boolean relativePaths

Constructor Detail

InitCommandback to summary
public InitCommand()

Method Detail

callback to summary
public Git call() throws GitAPIException

Implements java.util.concurrent.Callable.call.

Doc from java.util.concurrent.Callable.call.

Computes a result, or throws an exception if unable to do so.

Executes the Init command.

Returns:Git

a Git instance that owns the Repository that it wraps.

Annotations
@Override
setBareback to summary
public InitCommand setBare(boolean bare)

Set whether the repository is bare or not

Parameters
bare:boolean

whether the repository is bare or not

Returns:InitCommand

this instance

Exceptions
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
setDirectoryback to summary
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:File

the directory to init to

Returns:InitCommand

this instance

Exceptions
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
setFsback to summary
public InitCommand setFs(FS fs)

Set the file system abstraction to be used for repositories created by this command.

Parameters
fs:FS

the abstraction.

Returns:InitCommand

this (for chaining calls).

Since
4.10
setGitDirback to summary
public InitCommand setGitDir(File gitDir) throws IllegalStateException

Set the repository meta directory (.git)

Parameters
gitDir:File

the repository meta directory

Returns:InitCommand

this instance

Exceptions
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
setInitialBranchback to summary
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:String

initial branch name of the new repository

Returns:InitCommand

this

Exceptions
InvalidRefNameException:
if the branch name is not valid
Since
5.11
setRelativeDirsback to summary
public InitCommand setRelativeDirs(boolean relativePaths)

* Set whether the repository shall use relative paths for GIT_DIR and GIT_WORK_TREE

Parameters
relativePaths:boolean

if true, use relative paths for GIT_DIR and GIT_WORK_TREE

Returns:InitCommand

this

Since
7.2
validateDirsback to summary
private static void validateDirs(File directory, File gitDir, boolean bare) throws IllegalStateException