Class GitUtils
java.lang.Object
fr.paris.lutece.plugins.releaser.util.github.GitUtils
The Class GitUtils.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidcheckoutRepoBranch(org.eclipse.jgit.api.Git git, String sBranchName, CommandResult commandResult) Checkout repo branch.static voidcheckoutTag(org.eclipse.jgit.api.Git git, String strTagName, CommandResult commandResult) Checkout a tag in detached HEAD state.static org.eclipse.jgit.api.GitcloneRepo(String sClonePath, String sRepoURL, CommandResult commandResult, String strGitHubUserLogin, String strUserName, String strPassword) Clone repo.static voidcreateLocalBranch(org.eclipse.jgit.api.Git git, String sBranchName, CommandResult commandResult) Creates the local branch.static voidensureLocalBranch(org.eclipse.jgit.api.Git git, String strBranchName, CommandResult commandResult) Ensure a local tracking branch exists forstrBranchName.getBranchList(String repoUrl, File localRepo, CommandResult commandResult, String login, String pwd) static StringgetFileContent(String strFullName, String strPathFile, String strBranch, String strUserName, String strPassword) Gets the file content.static org.eclipse.jgit.api.GitGets the git.static StringgetLastCommitId(org.eclipse.jgit.api.Git git) Gets the last commit id.static StringgetLastLog(org.eclipse.jgit.api.Git git, int nMaxCommit) Gets the last log.The configured list of release-from branches that follow a master* counterpart (propertyConstanteUtils.PROPERTY_MERGE_BACK_BRANCHES, e.g.static StringgetRefBranch(org.eclipse.jgit.api.Git git, String sBranchName, CommandResult commandResult) Gets the ref branch.static StringgetRepoUrl(String strRepoUrl) Gets the repo url.getTagNameList(org.eclipse.jgit.api.Git git) Gets the tag name list.static StringgetTargetMasterBranch(String strBranchReleaseFrom) Derive the target master* branch from a release-from branch.static booleanisMergeBackBranch(String strBranch) Whether the given branch is one of the configured "follow master" branches (ConstanteUtils.PROPERTY_MERGE_BACK_BRANCHES).lsRemoteBranches(String repoUrl, String login, String pwd) List the remote branch names without cloning (git ls-remote --heads).static org.eclipse.jgit.api.MergeResultmergeBack(org.eclipse.jgit.api.Git git, String strSourceBranch, String strTargetMasterBranch, String strUserName, String strPassword, CommandResult commandResult) Merge back the source branch (or the last release tag if any) into the target master branch and push.static org.eclipse.jgit.api.MergeResultmergeOursStrategy(org.eclipse.jgit.api.Git git, String strBranchToMerge, String strMessage, CommandResult commandResult) Merge a branch into the current branch using the "ours" strategy.static org.eclipse.jgit.api.MergeResultmergeRepoBranch(org.eclipse.jgit.api.Git git, String strBranchToMerge) Merge repo branch.static org.eclipse.jgit.api.PullResultpullRepoBranch(org.eclipse.jgit.api.Git git, String sBranchName, String strUserName, String strPassword) Pull repo branch.static voidPush force.static voidpushTagOnly(org.eclipse.jgit.api.Git git, String strTagName, String strUserName, String strPassword, CommandResult commandResult) Push only a tag ref to origin, without pushing any branch.static GithubSearchResultsearchRepo(String strSearch, String strOrganization, String strUserName, String strPassword) Search repo.
-
Field Details
-
MASTER_BRANCH
The Constant MASTER_BRANCH.- See Also:
-
DEFAULT_RELEASE_BRANCH
The Constant DEVELOP_BRANCH.- See Also:
-
DEVELOP_BRANCH
The Constant DEVELOP_BRANCH — source branch of the develop/master flow, paired with MASTER_BRANCH.- See Also:
-
-
Constructor Details
-
GitUtils
public GitUtils()
-
-
Method Details
-
getTargetMasterBranch
Derive the target master* branch from a release-from branch. Only branches explicitly listed in theConstanteUtils.PROPERTY_MERGE_BACK_BRANCHESconfiguration are merged back into a master* counterpart, built by swapping the leadingDEVELOP_BRANCHprefix withMASTER_BRANCH(e.g.develop_core7→master_core7). Any other branch (including release/maintenance branches that merely start with "develop", e.g.develop-plugin-xxx-1.0.6-branch) has no master* counterpart and is released without a merge-back.- Parameters:
strBranchReleaseFrom- the source branch- Returns:
- the target master* branch, or
nullif no master* merge applies
-
getMergeBackBranches
The configured list of release-from branches that follow a master* counterpart (propertyConstanteUtils.PROPERTY_MERGE_BACK_BRANCHES, e.g.develop,develop_core7,develop7.x).- Returns:
- the list of branches (never null, possibly empty)
-
isMergeBackBranch
Whether the given branch is one of the configured "follow master" branches (ConstanteUtils.PROPERTY_MERGE_BACK_BRANCHES).- Parameters:
strBranch- the branch- Returns:
- true if the branch is in the configured list
-
cloneRepo
public static org.eclipse.jgit.api.Git cloneRepo(String sClonePath, String sRepoURL, CommandResult commandResult, String strGitHubUserLogin, String strUserName, String strPassword) Clone repo.- Parameters:
sClonePath- the s clone pathsRepoURL- the s repo URLcommandResult- the command resultstrGitHubUserLogin- the str git hub user loginstrUserName- the str user namestrPassword- the str password- Returns:
- the git
-
checkoutRepoBranch
public static void checkoutRepoBranch(org.eclipse.jgit.api.Git git, String sBranchName, CommandResult commandResult) Checkout repo branch.- Parameters:
git- the gitsBranchName- the s branch namecommandResult- the command result
-
createLocalBranch
public static void createLocalBranch(org.eclipse.jgit.api.Git git, String sBranchName, CommandResult commandResult) Creates the local branch.- Parameters:
git- the gitsBranchName- the s branch namecommandResult- the command result
-
getRefBranch
public static String getRefBranch(org.eclipse.jgit.api.Git git, String sBranchName, CommandResult commandResult) Gets the ref branch.- Parameters:
git- the gitsBranchName- the s branch namecommandResult- the command result- Returns:
- the ref branch
-
pushForce
public static void pushForce(org.eclipse.jgit.api.Git git, String strRefSpec, String strUserName, String strPassword) throws org.eclipse.jgit.api.errors.InvalidRemoteException, org.eclipse.jgit.api.errors.TransportException, org.eclipse.jgit.api.errors.GitAPIException Push force.- Parameters:
git- the gitstrRefSpec- the str ref specstrUserName- the str user namestrPassword- the str password- Throws:
org.eclipse.jgit.api.errors.InvalidRemoteException- the invalid remote exceptionorg.eclipse.jgit.api.errors.TransportException- the transport exceptionorg.eclipse.jgit.api.errors.GitAPIException- the git API exception
-
pullRepoBranch
public static org.eclipse.jgit.api.PullResult pullRepoBranch(org.eclipse.jgit.api.Git git, String sBranchName, String strUserName, String strPassword) throws IOException, org.eclipse.jgit.api.errors.WrongRepositoryStateException, org.eclipse.jgit.api.errors.InvalidConfigurationException, org.eclipse.jgit.api.errors.DetachedHeadException, org.eclipse.jgit.api.errors.InvalidRemoteException, org.eclipse.jgit.api.errors.CanceledException, org.eclipse.jgit.api.errors.RefNotFoundException, org.eclipse.jgit.api.errors.NoHeadException, org.eclipse.jgit.api.errors.TransportException, org.eclipse.jgit.api.errors.GitAPIException Pull repo branch.- Parameters:
git- the gitsBranchName- the s branch namestrUserName- the str user namestrPassword- the str password- Returns:
- the pull result
- Throws:
IOException- Signals that an I/O exception has occurred.org.eclipse.jgit.api.errors.WrongRepositoryStateException- the wrong repository state exceptionorg.eclipse.jgit.api.errors.InvalidConfigurationException- the invalid configuration exceptionorg.eclipse.jgit.api.errors.DetachedHeadException- the detached head exceptionorg.eclipse.jgit.api.errors.InvalidRemoteException- the invalid remote exceptionorg.eclipse.jgit.api.errors.CanceledException- the canceled exceptionorg.eclipse.jgit.api.errors.RefNotFoundException- the ref not found exceptionorg.eclipse.jgit.api.errors.NoHeadException- the no head exceptionorg.eclipse.jgit.api.errors.TransportException- the transport exceptionorg.eclipse.jgit.api.errors.GitAPIException- the git API exception
-
mergeRepoBranch
public static org.eclipse.jgit.api.MergeResult mergeRepoBranch(org.eclipse.jgit.api.Git git, String strBranchToMerge) throws IOException, org.eclipse.jgit.api.errors.WrongRepositoryStateException, org.eclipse.jgit.api.errors.InvalidConfigurationException, org.eclipse.jgit.api.errors.DetachedHeadException, org.eclipse.jgit.api.errors.InvalidRemoteException, org.eclipse.jgit.api.errors.CanceledException, org.eclipse.jgit.api.errors.RefNotFoundException, org.eclipse.jgit.api.errors.NoHeadException, org.eclipse.jgit.api.errors.TransportException, org.eclipse.jgit.api.errors.GitAPIException Merge repo branch.- Parameters:
git- the gitstrBranchToMerge- the str branch to merge- Returns:
- the merge result
- Throws:
IOException- Signals that an I/O exception has occurred.org.eclipse.jgit.api.errors.WrongRepositoryStateException- the wrong repository state exceptionorg.eclipse.jgit.api.errors.InvalidConfigurationException- the invalid configuration exceptionorg.eclipse.jgit.api.errors.DetachedHeadException- the detached head exceptionorg.eclipse.jgit.api.errors.InvalidRemoteException- the invalid remote exceptionorg.eclipse.jgit.api.errors.CanceledException- the canceled exceptionorg.eclipse.jgit.api.errors.RefNotFoundException- the ref not found exceptionorg.eclipse.jgit.api.errors.NoHeadException- the no head exceptionorg.eclipse.jgit.api.errors.TransportException- the transport exceptionorg.eclipse.jgit.api.errors.GitAPIException- the git API exception
-
getLastLog
public static String getLastLog(org.eclipse.jgit.api.Git git, int nMaxCommit) throws org.eclipse.jgit.api.errors.NoHeadException, org.eclipse.jgit.api.errors.GitAPIException Gets the last log.- Parameters:
git- the gitnMaxCommit- the n max commit- Returns:
- the last log
- Throws:
org.eclipse.jgit.api.errors.NoHeadException- the no head exceptionorg.eclipse.jgit.api.errors.GitAPIException- the git API exception
-
getLastCommitId
public static String getLastCommitId(org.eclipse.jgit.api.Git git) throws org.eclipse.jgit.api.errors.NoHeadException, org.eclipse.jgit.api.errors.GitAPIException Gets the last commit id.- Parameters:
git- the git- Returns:
- the last commit id
- Throws:
org.eclipse.jgit.api.errors.NoHeadException- the no head exceptionorg.eclipse.jgit.api.errors.GitAPIException- the git API exception
-
mergeBack
public static org.eclipse.jgit.api.MergeResult mergeBack(org.eclipse.jgit.api.Git git, String strSourceBranch, String strTargetMasterBranch, String strUserName, String strPassword, CommandResult commandResult) throws IOException, org.eclipse.jgit.api.errors.GitAPIException Merge back the source branch (or the last release tag if any) into the target master branch and push.- Parameters:
git- the gitstrSourceBranch- the source branch to merge from (e.g. "develop", "develop_core7")strTargetMasterBranch- the target master branch to merge into (e.g. "master", "master_core7")strUserName- the str user namestrPassword- the str passwordcommandResult- the command result- Returns:
- the merge result
- Throws:
IOException- Signals that an I/O exception has occurred.org.eclipse.jgit.api.errors.GitAPIException- the git API exception
-
searchRepo
public static GithubSearchResult searchRepo(String strSearch, String strOrganization, String strUserName, String strPassword) Search repo.- Parameters:
strSearch- the str searchstrOrganization- the str organizationstrUserName- the str user namestrPassword- the str password- Returns:
- the github search result
-
getFileContent
public static String getFileContent(String strFullName, String strPathFile, String strBranch, String strUserName, String strPassword) Gets the file content.- Parameters:
strFullName- the str full namestrPathFile- the str path filestrBranch- the str branchstrUserName- the str user namestrPassword- the str password- Returns:
- the file content
-
getTagNameList
Gets the tag name list.- Parameters:
git- the git- Returns:
- the tag name list
-
getRepoUrl
Gets the repo url.- Parameters:
strRepoUrl- the str repo url- Returns:
- the repo url
-
getGit
Gets the git.- Parameters:
strClonePath- the str clone path- Returns:
- the git
-
lsRemoteBranches
List the remote branch names without cloning (git ls-remote --heads). Lightweight : no working tree, no packfile, no disk usage.- Parameters:
repoUrl- the remote repository URLlogin- the credential loginpwd- the credential password- Returns:
- the list of remote branch names (e.g. "develop", "develop_core7"), empty on error
-
getBranchList
-
checkoutTag
public static void checkoutTag(org.eclipse.jgit.api.Git git, String strTagName, CommandResult commandResult) Checkout a tag in detached HEAD state. Used by the "release from tag" workflow : the tag's content becomes the working tree without moving any branch label.- Parameters:
git- the gitstrTagName- the tag name (without "refs/tags/" prefix)commandResult- the command result
-
pushTagOnly
public static void pushTagOnly(org.eclipse.jgit.api.Git git, String strTagName, String strUserName, String strPassword, CommandResult commandResult) Push only a tag ref to origin, without pushing any branch. Used by the "release from tag" workflow to publish the newly created stable tag while keeping the local detached commit out of the remote.- Parameters:
git- the gitstrTagName- the tag name (without "refs/tags/" prefix)strUserName- the str user namestrPassword- the str passwordcommandResult- the command result
-
ensureLocalBranch
public static void ensureLocalBranch(org.eclipse.jgit.api.Git git, String strBranchName, CommandResult commandResult) Ensure a local tracking branch exists forstrBranchName. JGit's checkout requires a local ref; a fresh clone only hasrefs/remotes/origin/*. If the local branch already exists, does nothing. If only the remote ref exists, creates a local tracking branch fromorigin/<branchName>. Fails viaReleaserUtils.addTechnicalError(fr.paris.lutece.plugins.releaser.util.CommandResult, java.lang.String, java.lang.Exception)if neither exists.- Parameters:
git- the gitstrBranchName- the branch name (withoutrefs/heads/ororigin/prefix)commandResult- the command result
-
mergeOursStrategy
public static org.eclipse.jgit.api.MergeResult mergeOursStrategy(org.eclipse.jgit.api.Git git, String strBranchToMerge, String strMessage, CommandResult commandResult) Merge a branch into the current branch using the "ours" strategy. Records the merge in history without changing the working tree : the next merge from the same source will treat its commits as already integrated, which prevents future conflicts on lines both branches modified independently.- Parameters:
git- the gitstrBranchToMerge- the branch to mark as integrated (e.g. "develop", "develop_core7")strMessage- the merge commit messagecommandResult- the command result- Returns:
- the merge result, or
nullif an error occurred
-