public final class JkGit extends JkAbstractProcess<JkGit>
Modifier and Type | Class and Description |
---|---|
static class |
JkGit.FileList |
static class |
JkGit.Tag |
CURRENT_JAVA_DIR
Modifier and Type | Method and Description |
---|---|
JkGit |
copy() |
JkGit.FileList |
diiff(java.lang.String commitFrom,
java.lang.String commitTo)
Executes a Git diff command between the specified commits and returns a list of files changed.
|
java.lang.String |
extractSuffixFromLastCommitMessage(java.lang.String prefix)
Extracts information from the last commit message title.
|
java.util.List<java.lang.String> |
getCommitMessagesSinceLastTag()
Returns the distinct last commit messages since last tag in the current branch.
|
java.lang.String |
getCurrentBranch()
Returns the current branch name.
|
java.lang.String |
getCurrentCommit()
Returns the current commit of the Git repository.
|
JkVersion |
getJkVersionFromTag()
Returns the JkVersion extracted from the tags of the current commit.
|
java.lang.String |
getLastCommitMessage()
Returns the last commit message.
|
java.util.List<java.lang.String> |
getLastCommitMessageMultiLine()
Returns the last commit message as a list of strings.
|
java.lang.String |
getLatestTag()
Returns the latest tag in the Git repository.
|
java.lang.String |
getRemoteDefaultBranch(java.lang.String repoUrl)
Retrieves the default branch of a remote Git repository specified by its URL.
|
java.util.List<java.lang.String> |
getRemoteTagAsStrings(java.lang.String repoUrl)
Retrieves a list of tags from a remote Git repository.
|
java.lang.String |
getRemoteTagCommit(java.lang.String repoUrl,
java.lang.String tag)
Retrieves the commit hash associated with a specified tag from a remote Git repository.
|
java.util.List<JkGit.Tag> |
getRemoteTags(java.lang.String repoUrl)
Retrieves a list of tags from a remote Git repository.
|
java.lang.String |
getRemoteUrl()
Retrieves the URL of the "origin" remote for the Git repository.
|
java.util.List<java.lang.String> |
getTagsOnCurrentCommit()
Returns a list of tags associated with the current commit.
|
java.lang.String |
getVersionFromCommitMessage(java.lang.String prefixKeyword)
Returns version according the last commit message.
|
java.lang.String |
getVersionFromTag()
Returns version according the tags found on current commit.
|
java.lang.String |
getVersionFromTag(java.lang.String prefix)
Returns version according the tags found on current commit.
|
boolean |
isOnGitRepo() |
boolean |
isSyncWithRemote()
Checks if the local branch is in sync with the remote branch.
|
boolean |
isWorkspaceDirty()
Checks if the workspace is dirty by executing the 'git diff HEAD --stat' command
and checking if the output is empty.
|
static JkGit |
of()
Creates a new instance of JkGit pointing on the current working directory.
|
static JkGit |
of(java.nio.file.Path dir)
Creates a new JkGit instance pointing on the specified working directory.
|
static JkGit |
of(java.lang.String dir)
Creates a new JkGit instance pointing on the specified working directory.
|
JkGit |
tag(java.lang.String tagName)
Adds a tag at the HEAD of the current branch.
|
JkGit |
tagAndPush(java.lang.String name)
Puts a tag at the HEAD of the current branch and pushes it to the remote repository.
|
void |
tagRemote()
Tags the remote repository with a new tag.
|
addParams, addParams, addParamsAsCmdLine, addParamsAt, addParamsAt, addParamsIf, customizeCommand, exec, execAsync, execCmd, execCmdLine, getParamAt, getParams, getWorkingDir, inheritJkLogOptions, isFailOnError, redirectErrorStream, removeParam, run, setCollectStderr, setCollectStdout, setDestroyAtJvmShutdown, setEnv, setFailOnError, setInheritIO, setLogCommand, setLogWithJekaDecorator, setParamAt, setWorkingDir, setWorkingDir, toString
public static JkGit of(java.nio.file.Path dir)
public static JkGit of(java.lang.String dir)
public static JkGit of()
public java.lang.String getCurrentBranch()
public java.lang.String getRemoteUrl()
public boolean isOnGitRepo()
public boolean isSyncWithRemote()
public boolean isWorkspaceDirty()
public java.lang.String getCurrentCommit()
public java.util.List<java.lang.String> getTagsOnCurrentCommit()
public java.util.List<java.lang.String> getLastCommitMessageMultiLine()
public java.lang.String getLastCommitMessage()
public java.lang.String extractSuffixFromLastCommitMessage(java.lang.String prefix)
This method splits the commit message in separated words, then looks for the fist word starting with the specified prefix. The returned suffix is the word found minus the prefix.
For example, if the title is 'Release:0.9.5.RC1 : Rework Dependencies', then invoking this method with 'Release:' argument will return '0.9.5.RC1'.
This method returns null
if no such prefix found.
public JkGit tagAndPush(java.lang.String name)
public JkGit tag(java.lang.String tagName)
public java.lang.String getVersionFromCommitMessage(java.lang.String prefixKeyword)
If the commit message contains a word starting with the specified prefix keyword then the substring following this suffix will be returned.
If no such prefix found, then a version formatted as [branch]-SNAPSHOT will be returned
public java.lang.String getVersionFromTag(java.lang.String prefix)
If the current commit has a tag starting by prefix
and the workspace is not dirty,
then the version is this tag name on the current commit.
If there is many tags starting with prefix
on the current commit, only the last one in alphabetical order is
taken in account.
If no tag starting with prefix
is present on the current commit or the workspace is dirty,
the version will value [branch]-SNAPSHOT.
If prefix
is empty, any tag will match.
public java.lang.String getVersionFromTag()
getVersionFromTag(String)
public JkVersion getJkVersionFromTag()
getVersionFromTag(String)
public java.util.List<java.lang.String> getCommitMessagesSinceLastTag()
public java.lang.String getLatestTag()
public void tagRemote()
This method performs the following steps:
public JkGit.FileList diiff(java.lang.String commitFrom, java.lang.String commitTo)
commitFrom
- The starting commit of the diff.commitTo
- The ending commit of the diff. This can value HEAD.public java.lang.String getRemoteTagCommit(java.lang.String repoUrl, java.lang.String tag)
tag
- The tag name whose associated commit is to be fetched.
If blank, the HEAD reference will be used.public java.util.List<java.lang.String> getRemoteTagAsStrings(java.lang.String repoUrl)
public java.util.List<JkGit.Tag> getRemoteTags(java.lang.String repoUrl)
repoUrl
- The URL of the remote Git repository to fetch tags from.public java.lang.String getRemoteDefaultBranch(java.lang.String repoUrl)
public JkGit copy()
copy
in class JkAbstractProcess<JkGit>