{
String releaseLabel = "";
try
{
JGitFlowReporter reporter = flow.getReporter();
//get the release branch
List<Ref> releaseBranches = GitHelper.listBranchesWithPrefix(flow.git(), flow.getReleaseBranchPrefix());
if (releaseBranches.isEmpty())
{
throw new JGitFlowReleaseException("Could not find release branch!");
}
//there can be only one
String rheadPrefix = Constants.R_HEADS + flow.getReleaseBranchPrefix();
Ref releaseBranch = releaseBranches.get(0);
releaseLabel = releaseBranch.getName().substring(releaseBranch.getName().indexOf(rheadPrefix) + rheadPrefix.length());
String prefixedBranchName = flow.getReleaseBranchPrefix() + releaseLabel;
//make sure we're on the release branch
if(getLogger().isDebugEnabled())
{
getLogger().debug("checking out release branch: " + prefixedBranchName);
}
flow.git().checkout().setName(prefixedBranchName).call();
//make sure we're not behind remote
if(GitHelper.remoteBranchExists(flow.git(), prefixedBranchName, reporter))
{
if(GitHelper.localBranchBehindRemote(flow.git(),prefixedBranchName,reporter))
{
reporter.errorText("release-finish","local branch '" + prefixedBranchName + "' is behind the remote branch");
reporter.flush();
throw new BranchOutOfDateException("local branch '" + prefixedBranchName + "' is behind the remote branch");
}
}
if(GitHelper.remoteBranchExists(flow.git(), flow.getDevelopBranchName(), flow.getReporter()))
{
if(ctx.isPullDevelop())
{
reporter.debugText("finishRelease", "pulling develop before remote behind check");
reporter.flush();
flow.git().checkout().setName(flow.getDevelopBranchName()).call();
flow.git().pull().call();
flow.git().checkout().setName(prefixedBranchName).call();
}
if(GitHelper.localBranchBehindRemote(flow.git(),flow.getDevelopBranchName(),flow.getReporter()))
{
reporter.errorText("release-finish","local branch '" + flow.getDevelopBranchName() + "' is behind the remote branch");
reporter.flush();
throw new BranchOutOfDateException("local branch '" + flow.getDevelopBranchName() + "' is behind the remote branch");
}
}
if(GitHelper.remoteBranchExists(flow.git(), flow.getMasterBranchName(), flow.getReporter()))
{
if(ctx.isPullMaster())
{
reporter.debugText("finishRelease", "pulling master before remote behind check");
reporter.flush();
flow.git().checkout().setName(flow.getMasterBranchName()).call();
flow.git().pull().call();
flow.git().checkout().setName(prefixedBranchName).call();
}
if(GitHelper.localBranchBehindRemote(flow.git(),flow.getMasterBranchName(),flow.getReporter()))
{
reporter.errorText("release-finish","local branch '" + flow.getMasterBranchName() + "' is behind the remote branch");
reporter.flush();
throw new BranchOutOfDateException("local branch '" + flow.getMasterBranchName() + "' is behind the remote branch");
}
}
//get the reactor projects for release