Package com.jk.core.scm
Class JKGitWrapper
java.lang.Object
com.jk.core.scm.JKGitWrapper
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
ConstructorsConstructorDescriptionThis method constructs a newJKGitWrapper
.JKGitWrapper
(Properties properties) This method constructs a newJKGitWrapper
using the provided properties. -
Method Summary
Modifier and TypeMethodDescriptionvoid
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
close()
This method closes the Git repository and performs necessary cleanup.void
commit()
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.This method sets the local repository path using aFile
object.This method sets the local repository path using a string.void
log()
This method displays the commit history (log) of the repository.static void
This method provides an example usage of the JKGitWrapper class.This method sets the password for authentication.org.eclipse.jgit.api.Git
pull()
This method pulls the changes from the remote repository to the local repository.void
push()
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
This method tags a commit in the repository.This method sets the repository URL.This method sets the user name for authentication.
-
Constructor Details
-
JKGitWrapper
public JKGitWrapper()This method constructs a newJKGitWrapper
. -
JKGitWrapper
This method constructs a newJKGitWrapper
using the provided properties.- Parameters:
properties
- Specifies the properties used for configuration.
-
-
Method Details
-
url
This method sets the repository URL.- Parameters:
url
- Specifies the repository URL.- Returns:
- the updated
JKGitWrapper
instance.
-
user
This method sets the user name for authentication.- Parameters:
userName
- Specifies the user name.- Returns:
- the updated
JKGitWrapper
instance.
-
password
This method sets the password for authentication.- Parameters:
password
- Specifies the password.- Returns:
- the updated
JKGitWrapper
instance.
-
localPath
This method sets the local repository path using a string.- Parameters:
localPath
- Specifies the repository local path.- Returns:
- the updated
JKGitWrapper
instance.
-
localPath
This method sets the local repository path using aFile
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
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
This method gets the commit message.- Returns:
- the commit message.
-
setMessage
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
This method gets the repository local path.- Returns:
- the repository local path.
-
main
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.
-