MergeResult masterResult = new MergeResult(null,null,new ObjectId[] { null, null }, MergeResult.MergeStatus.ALREADY_UP_TO_DATE,MergeStrategy.RESOLVE,null);
try
{
if (fetch)
{
RefSpec developSpec = new RefSpec("+" + Constants.R_HEADS + gfConfig.getDevelop() + ":" + Constants.R_REMOTES + "origin/" + gfConfig.getDevelop());
RefSpec masterSpec = new RefSpec("+" + Constants.R_HEADS + gfConfig.getMaster() + ":" + Constants.R_REMOTES + "origin/" + gfConfig.getMaster());
git.fetch().setRemote(Constants.DEFAULT_REMOTE_NAME).setRefSpecs(masterSpec).call();
git.fetch().setRemote(Constants.DEFAULT_REMOTE_NAME).setRefSpecs(developSpec).call();
git.fetch().setRemote(Constants.DEFAULT_REMOTE_NAME).call();
}
if (GitHelper.remoteBranchExists(git, gfConfig.getMaster()))
{
requireLocalBranchNotBehindRemote(gfConfig.getMaster());
}
if (GitHelper.remoteBranchExists(git, gfConfig.getDevelop()))
{
requireLocalBranchNotBehindRemote(gfConfig.getDevelop());
}
Ref releaseBranch = GitHelper.getLocalBranch(git, prefixedReleaseName);
RevCommit releaseCommit = GitHelper.getLatestCommit(git, prefixedReleaseName);
/*
try to merge into master
in case a previous attempt to finish this release branch has failed,
but the merge into master was successful, we skip it now
*/
if (!GitHelper.isMergedInto(git, prefixedReleaseName, gfConfig.getMaster()))
{
git.checkout().setName(gfConfig.getMaster()).call();
if (squash)
{
masterResult = git.merge().setSquash(true).include(releaseBranch).call();
git.commit().call();
}
else
{
masterResult = git.merge().setFastForward(MergeCommand.FastForwardMode.NO_FF).include(releaseBranch).call();
}
}
if (!noTag)
{
/*
try to tag the release
in case a previous attempt to finish this release branch has failed,
but the tag was successful, we skip it now
*/
String tagName = gfConfig.getPrefixValue(JGitFlowConstants.PREFIXES.VERSIONTAG.configKey()) + releaseName;
if (!GitHelper.tagExists(git, tagName))
{
git.tag().setName(tagName).setMessage(message).setObjectId(releaseCommit).call();
}
}
/*
try to merge into develop
in case a previous attempt to finish this release branch has failed,
but the merge into develop was successful, we skip it now
*/
if (!GitHelper.isMergedInto(git, prefixedReleaseName, gfConfig.getDevelop()))
{
git.checkout().setName(gfConfig.getDevelop()).call();
if (squash)
{
developResult = git.merge().setSquash(true).include(releaseBranch).call();
git.commit().call();
}
else
{
developResult = git.merge().setFastForward(MergeCommand.FastForwardMode.NO_FF).include(releaseBranch).call();
}
}
if (push)
{
//push to develop
RefSpec developSpec = new RefSpec(gfConfig.getDevelop());
git.push().setRemote(Constants.DEFAULT_REMOTE_NAME).setRefSpecs(developSpec).call();
//push to master
RefSpec masterSpec = new RefSpec(gfConfig.getMaster());
git.push().setRemote(Constants.DEFAULT_REMOTE_NAME).setRefSpecs(masterSpec).call();
if (!noTag)
{
git.push().setRemote(Constants.DEFAULT_REMOTE_NAME).setPushTags().call();
}
if (GitHelper.remoteBranchExists(git, prefixedReleaseName))
{
RefSpec branchSpec = new RefSpec(prefixedReleaseName);
git.push().setRemote(Constants.DEFAULT_REMOTE_NAME).setRefSpecs(branchSpec).call();
}
}
if (!keepBranch)
{
git.checkout().setName(gfConfig.getDevelop()).call();
git.branchDelete().setForce(true).setBranchNames(prefixedReleaseName).call();
if (push && GitHelper.remoteBranchExists(git, prefixedReleaseName))
{
RefSpec deleteSpec = new RefSpec(":" + Constants.R_HEADS + prefixedReleaseName);
git.push().setRemote(Constants.DEFAULT_REMOTE_NAME).setRefSpecs(deleteSpec).call();
}
}
git.checkout().setName(gfConfig.getDevelop()).call();