String prefixedHotfixName = gfConfig.getPrefixValue(JGitFlowConstants.PREFIXES.HOTFIX.configKey()) + hotfixName;
requireLocalBranchExists(prefixedHotfixName);
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(), reporter))
{
requireLocalBranchNotBehindRemote(gfConfig.getMaster());
}
if (GitHelper.remoteBranchExists(git, gfConfig.getDevelop(), reporter))
{
requireLocalBranchNotBehindRemote(gfConfig.getDevelop());
}
Ref hotfixBranch = GitHelper.getLocalBranch(git, prefixedHotfixName);
RevCommit hotfixCommit = GitHelper.getLatestCommit(git, prefixedHotfixName);
/*
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, prefixedHotfixName, gfConfig.getMaster()))
{
git.checkout().setName(gfConfig.getMaster()).call();
masterResult = git.merge().setFastForward(MergeCommand.FastForwardMode.NO_FF).include(hotfixBranch).call();
if(masterResult.getMergeStatus().isSuccessful())
{
git.commit().setMessage("merging " + prefixedHotfixName + "' into master").call();
}
}