Class Git

java.lang.Object
org.eclipse.jgit.api.Git
All Implemented Interfaces:
AutoCloseable

public class Git extends Object implements AutoCloseable
Offers a "GitPorcelain"-like API to interact with a git repository.

The GitPorcelain commands are described in the Git Documentation.

This class only offers methods to construct so-called command classes. Each GitPorcelain command is represented by one command class.
Example: this class offers a commit() method returning an instance of the CommitCommand class. The CommitCommand class has setters for all the arguments and options. The CommitCommand class also has a call method to actually execute the commit. The following code show's how to do a simple commit:

 Git git = new Git(myRepo);
 git.commit().setMessage("Fix393").setAuthor(developerIdent).call();
 
All mandatory parameters for commands have to be specified in the methods of this class, the optional parameters have to be specified by the setter-methods of the Command class.

This class is intended to be used internally (e.g. by JGit tests) or by external components (EGit, third-party tools) when they need exactly the functionality of a GitPorcelain command. There are use-cases where this class is not optimal and where you should use the more low-level JGit classes. The methods in this class may for example offer too much functionality or they offer the functionality with the wrong arguments.

  • Field Details

    • repo

      private final Repository repo
      The git repository this class is interacting with
    • closeRepo

      private final boolean closeRepo
  • Constructor Details

    • Git

      public Git(Repository repo)
      Construct a new Git object which can interact with the specified git repository.

      All command classes returned by methods of this class will always interact with this git repository.

      The caller is responsible for closing the repository; close() on this instance does not close the repo.

      Parameters:
      repo - the git repository this class is interacting with; null is not allowed.
    • Git

      Git(Repository repo, boolean closeRepo)
  • Method Details