Class JKGitWrapper

java.lang.Object
com.jk.core.scm.JKGitWrapper

public class JKGitWrapper extends Object
This class provides a convenient interface to interact with Git repositories, including creating, cloning, committing, pushing, and other related operations.
Version:
1.0
Author:
Dr. Jalal H. Kiswani
  • Constructor Summary

    Constructors
    Constructor
    Description
    This method constructs a new JKGitWrapper.
    This method constructs a new JKGitWrapper using the provided properties.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    add()
    This method adds files to the staging area for the next commit.
    void
    This method adds all changes to the staging area, commits the changes with a default or provided message, and pushes the committed changes to the remote repository.
    org.eclipse.jgit.api.Git
    This method clone a remote Git repository.
    void
    This method closes the Git repository and performs necessary cleanup.
    void
    This method commits the changes in the repository.
    org.eclipse.jgit.api.Git
    This method creates a new Git repository.
    org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider
    This method retrieves the credentials for authentication to the remote repository.
    org.eclipse.jgit.api.Git
    This method retrieves the Git instance representing the current repository reference.
    This method gets the repository local path.
    This method gets the commit message.
    localPath(File localPath)
    This method sets the local repository path using a File object.
    localPath(String localPath)
    This method sets the local repository path using a string.
    void
    log()
    This method displays the commit history (log) of the repository.
    static void
    main(String[] args)
    This method provides an example usage of the JKGitWrapper class.
    password(String password)
    This method sets the password for authentication.
    org.eclipse.jgit.api.Git
    This method pulls the changes from the remote repository to the local repository.
    void
    This method pushes the changes in the repository to the remote repository.
    void
    setMessage(String message)
    This method sets the commit message.
    org.eclipse.jgit.revwalk.RevTag
    tag(String name, String message)
    This method tags a commit in the repository.
    url(String url)
    This method sets the repository URL.
    user(String userName)
    This method sets the user name for authentication.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • JKGitWrapper

      public JKGitWrapper()
      This method constructs a new JKGitWrapper.
    • JKGitWrapper

      public JKGitWrapper(Properties properties)
      This method constructs a new JKGitWrapper using the provided properties.
      Parameters:
      properties - Specifies the properties used for configuration.
  • Method Details

    • url

      public JKGitWrapper url(String url)
      This method sets the repository URL.
      Parameters:
      url - Specifies the repository URL.
      Returns:
      the updated JKGitWrapper instance.
    • user

      public JKGitWrapper user(String userName)
      This method sets the user name for authentication.
      Parameters:
      userName - Specifies the user name.
      Returns:
      the updated JKGitWrapper instance.
    • password

      public JKGitWrapper password(String password)
      This method sets the password for authentication.
      Parameters:
      password - Specifies the password.
      Returns:
      the updated JKGitWrapper instance.
    • localPath

      public JKGitWrapper localPath(String localPath)
      This method sets the local repository path using a string.
      Parameters:
      localPath - Specifies the repository local path.
      Returns:
      the updated JKGitWrapper instance.
    • localPath

      public JKGitWrapper localPath(File localPath)
      This method sets the local repository path using a File object.
      Parameters:
      localPath - Specifies the repository local path.
      Returns:
      the updated JKGitWrapper instance.
    • createRepo

      public org.eclipse.jgit.api.Git createRepo()
      This method creates a new Git repository.
      Returns:
      the Git instance representing the newly created repository.
    • cloneRepo

      public org.eclipse.jgit.api.Git cloneRepo()
      This method clone a remote Git repository.
      Returns:
      the Git instance representing the cloned repository.
    • tag

      public org.eclipse.jgit.revwalk.RevTag tag(String name, String message)
      This method tags a commit in the repository.
      Parameters:
      name - Specifies the tag name.
      message - Specifies the tag message.
      Returns:
      the RevTag instance representing the created tag.
    • commit

      public void commit()
      This method commits the changes in the repository.
    • getMessage

      public String getMessage()
      This method gets the commit message.
      Returns:
      the commit message.
    • setMessage

      public void setMessage(String message)
      This method sets the commit message.
      Parameters:
      message - Specifies the new message.
    • push

      public void push()
      This method pushes the changes in the repository to the remote repository.
    • pull

      public org.eclipse.jgit.api.Git pull()
      This method pulls the changes from the remote repository to the local repository.
      Returns:
      the Git instance representing the updated repository.
    • add

      public void add()
      This method adds files to the staging area for the next commit.
    • log

      public void log()
      This method displays the commit history (log) of the repository.
    • getCrednetials

      public org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider getCrednetials()
      This method retrieves the credentials for authentication to the remote repository.
      Returns:
      the UsernamePasswordCredentialsProvider instance containing the credentials.
    • getLocalPath

      public File getLocalPath()
      This method gets the repository local path.
      Returns:
      the repository local path.
    • main

      public static void main(String[] args) throws Exception
      This method provides an example usage of the JKGitWrapper class.

      It demonstrates how to create, add files, commit changes, and push to a Git repository.

      Parameters:
      args - the command line arguments.
      Throws:
      Exception - if an exception occurs during the Git operations.
    • addCommitPush

      public void addCommitPush()
      This method adds all changes to the staging area, commits the changes with a default or provided message, and pushes the committed changes to the remote repository.

      This method combines the steps of adding, committing, and pushing.

    • close

      public void close()
      This method closes the Git repository and performs necessary cleanup.
    • getGitReference

      public org.eclipse.jgit.api.Git getGitReference()
      This method retrieves the Git instance representing the current repository reference.
      Returns:
      the Git instance representing the repository.