Map<String, String> originalVersions = projectHelper.getOriginalVersions(reactorProjects);
JGitFlow flow = null;
String hotfixLabel = "";
MavenJGitFlowConfiguration config = null;
try
{
flow = JGitFlow.getOrInit(ctx.getBaseDir(), ctx.getFlowInitContext());
if(ctx.isPush() || !ctx.isNoTag())
{
ensureOrigin(reactorProjects, flow);
}
config = configManager.getConfiguration(flow.git());
hotfixLabel = getHotfixLabel(ctx, reactorProjects, config);
flow.hotfixStart(hotfixLabel).call();
}
catch (HotfixBranchExistsException e)
{
try
{
List<Ref> refs = GitHelper.listBranchesWithPrefix(flow.git(),flow.getHotfixBranchPrefix());
boolean foundOurRelease = false;
for(Ref ref : refs)
{
if(ref.getName().equals(Constants.R_HEADS + flow.getHotfixBranchPrefix() + hotfixLabel))
{
foundOurRelease = true;
break;
}
}
if(foundOurRelease)
{
//since the release branch already exists, just check it out
flow.git().checkout().setName(flow.getHotfixBranchPrefix() + hotfixLabel).call();
}
else
{
throw new JGitFlowReleaseException("Error starting hotfix: " + e.getMessage(), e);
}
}
catch (GitAPIException e1)
{
throw new JGitFlowReleaseException("Error checking out existing hotfix branch: " + e1.getMessage(), e1);
}
catch (JGitFlowGitAPIException e1)
{
e1.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
}
}
catch (JGitFlowException e)
{
throw new JGitFlowReleaseException("Error starting hotfix: " + e.getMessage(), e);
}
catch (IOException e)
{
throw new JGitFlowReleaseException("Error starting hotfix: " + e.getMessage(), e);
}
updatePomsWithHotfixVersion(ctx, reactorProjects, config);
commitAllChanges(flow.git(), "updating poms for " + hotfixLabel + " hotfix");
try
{
//save original versions to file so we can use them when we finish
config.setPreHotfixVersions(originalVersions);
configManager.saveConfiguration(config, flow.git());
}
catch (IOException e)
{
//just ignore for now