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 newJKGitWrapperusing the provided properties. -
Method Summary
Modifier and TypeMethodDescriptionvoidadd()This method adds files to the staging area for the next commit.voidThis 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.GitThis method clone a remote Git repository.voidclose()This method closes the Git repository and performs necessary cleanup.voidcommit()This method commits the changes in the repository.org.eclipse.jgit.api.GitThis method creates a new Git repository.org.eclipse.jgit.transport.UsernamePasswordCredentialsProviderThis method retrieves the credentials for authentication to the remote repository.org.eclipse.jgit.api.GitThis 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 aFileobject.This method sets the local repository path using a string.voidlog()This method displays the commit history (log) of the repository.static voidThis method provides an example usage of the JKGitWrapper class.This method sets the password for authentication.org.eclipse.jgit.api.Gitpull()This method pulls the changes from the remote repository to the local repository.voidpush()This method pushes the changes in the repository to the remote repository.voidsetMessage(String message) This method sets the commit message.org.eclipse.jgit.revwalk.RevTagThis 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 newJKGitWrapperusing 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
JKGitWrapperinstance.
-
user
This method sets the user name for authentication.- Parameters:
userName- Specifies the user name.- Returns:
- the updated
JKGitWrapperinstance.
-
password
This method sets the password for authentication.- Parameters:
password- Specifies the password.- Returns:
- the updated
JKGitWrapperinstance.
-
localPath
This method sets the local repository path using a string.- Parameters:
localPath- Specifies the repository local path.- Returns:
- the updated
JKGitWrapperinstance.
-
localPath
This method sets the local repository path using aFileobject.- Parameters:
localPath- Specifies the repository local path.- Returns:
- the updated
JKGitWrapperinstance.
-
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
RevTaginstance 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
UsernamePasswordCredentialsProviderinstance 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.
-