Class Git

java.lang.Object
org.jenkinsci.plugins.gitclient.Git
All Implemented Interfaces:
Serializable

public class Git extends Object implements Serializable
Git repository access class. Provides local and remote access to a git repository through a GitClient implementation. Current git implementations include either command line git ("git" - CliGitAPIImpl) or JGit ("jgit" - JGitAPIImpl). The command line git implementation requires a separately installed git program. The command line git implementation is the current reference implementation. The JGit implementation is bundled entirely within the git client plugin and does not require any external programs. The JGit implementation is not yet functionally complete, though it handles most use cases.
See Also:
  • Field Details

    • USE_CLI

      public static final boolean USE_CLI
      Constant which controls the default implementation to be used. USE_CLI=Boolean.valueOf(System.getProperty(Git.class.getName() + ".useCLI", "true")). Uses command line implementation (CliGitAPIImpl) by default.
  • Constructor Details

    • Git

      public Git(TaskListener listener, EnvVars env)
      Constructor for a Git object. Either Git.with(listener, env) or new Git(listener, env) can be used to construct a Git object.
      Parameters:
      listener - a TaskListener which can be used to monitor git implementation operations
      env - a EnvVars which provides environment values to the git implementation
  • Method Details

    • with

      public static Git with(TaskListener listener, EnvVars env)
      Fluent constructor for a Git object. Either Git.with(listener, env) or new Git(listener, env) can be used to construct a Git object.
      Parameters:
      listener - a TaskListener which can be used to monitor git implementation operations
      env - a EnvVars which provides environment values to the git implementation
      Returns:
      a Git object for repository access
    • in

      public Git in(File repository)
      Defines the local directory containing the git repository which will be used. For repositories with a working directory, repository is the parent of the .git directory. For bare repositories, repository is the parent of the objects directory.
      Parameters:
      repository - File of the git repository
      Returns:
      a Git object for repository access
    • in

      public Git in(FilePath repository)
      Defines the FilePath (remotable directory) containing the git repository which will be used. For repositories with a working directory, repository is the parent of the .git directory. For bare repositories, repository is the parent of the objects directory.
      Parameters:
      repository - FilePath of the git repository.
      Returns:
      a Git object for repository access
    • using

      public Git using(String exe)
      Set the (node/environment specific) git executable to be used. If not set, JGit implementation will be used. When default is used, it assumes the caller does not rely on unimplemented CLI methods.
      Parameters:
      exe - either "git" or "jgit"
      Returns:
      Git object for repository access
    • withHostKeyVerifierFactory

      public Git withHostKeyVerifierFactory(HostKeyVerifierFactory hostKeyFactory)
    • getClient

      public GitClient getClient() throws IOException, InterruptedException
      GitClient implementation. The GitClient interface provides the key operations which can be performed on a git repository.
      Returns:
      a GitClient for git operations on the repository
      Throws:
      IOException - if any IO failure
      InterruptedException - if interrupted.