String prefixedReleaseName = gfConfig.getPrefixValue(JGitFlowConstants.PREFIXES.RELEASE.configKey()) + releaseName;
requireLocalBranchExists(prefixedReleaseName);
requireCleanWorkingTree();
MergeResult developResult = new MergeResult(null, null, new ObjectId[]{null, null}, MergeResult.MergeStatus.ALREADY_UP_TO_DATE, MergeStrategy.RESOLVE, null);
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);
if(!noMerge)
{
/*
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();
reporter.infoText(getCommandName(), "merging '" + prefixedReleaseName + "' into master...");
if (squash)
{
reporter.infoText(getCommandName(), "squashing merge");
masterResult = git.merge().setSquash(true).include(releaseBranch).call();
if(masterResult.getMergeStatus().isSuccessful())
{
git.commit().setMessage("squashing " + prefixedReleaseName + "' into master").call();
}
}
else
{
masterResult = git.merge().setFastForward(MergeCommand.FastForwardMode.NO_FF).include(releaseBranch).call();
if(masterResult.getMergeStatus().isSuccessful())
{
git.commit().setMessage("merging " + prefixedReleaseName + "' into master").call();
}
}
}
reporter.mergeResult(getCommandName(), masterResult);
if (!masterResult.getMergeStatus().isSuccessful())
{
reporter.errorText(getCommandName(), "merge into master was not successful! Aborting the release...");
if (masterResult.getMergeStatus().equals(MergeResult.MergeStatus.CONFLICTING))
{
reporter.errorText(getCommandName(), "please resolve your merge conflicts and re-run " + getCommandName());
}
else
{