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, prefixedHotfixName, reporter))
{
requireLocalBranchNotBehindRemote(prefixedHotfixName);
}
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 (!noTag && masterResult.getMergeStatus().isSuccessful())
{
/*
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()) + hotfixName;
if (!GitHelper.tagExists(git, tagName))
{
reporter.infoText(
getCommandName(),
String.format(
"tagging hotfix with name: <%s>. On branch (%s). merge status (%s)",
tagName,
git.getRepository( ).getFullBranch(),
masterResult.getMergeStatus( )
)
);
git.tag().setName(tagName).setMessage(getScmMessagePrefix() + message).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, prefixedHotfixName, gfConfig.getDevelop()))
{
git.checkout().setName(gfConfig.getDevelop()).call();
developResult = git.merge().setFastForward(MergeCommand.FastForwardMode.NO_FF).include(hotfixBranch).call();
}
if (push && masterResult.getMergeStatus().isSuccessful() && developResult.getMergeStatus().isSuccessful())
{
//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, prefixedHotfixName, reporter))
{
RefSpec branchSpec = new RefSpec(prefixedHotfixName);
git.push().setRemote(Constants.DEFAULT_REMOTE_NAME).setRefSpecs(branchSpec).call();
}
}
if (!keepBranch && masterResult.getMergeStatus().isSuccessful() && developResult.getMergeStatus().isSuccessful())
{
git.checkout().setName(gfConfig.getDevelop()).call();
git.branchDelete().setForce(true).setBranchNames(prefixedHotfixName).call();
if (push && GitHelper.remoteBranchExists(git, prefixedHotfixName, reporter))