{
flow = jGitFlowProvider.gitFlow();
}
catch (JGitFlowException e)
{
throw new MavenJGitFlowException(e);
}
ReleaseContext ctx = contextProvider.getContext();
String featureName = StringUtils.defaultString(ctx.getDefaultFeatureName());
if (StringUtils.isBlank(featureName))
{
String currentBranch = null;
try
{
currentBranch = flow.git().getRepository().getBranch();
getLogger().debug("Current Branch is: " + currentBranch);
}
catch (IOException e)
{
throw new MavenJGitFlowException(e);
}
getLogger().debug("Feature Prefix is: " + flow.getFeatureBranchPrefix());
getLogger().debug("Branch starts with feature prefix?: " + currentBranch.startsWith(flow.getFeatureBranchPrefix()));
if (currentBranch.startsWith(flow.getFeatureBranchPrefix()))
{
featureName = currentBranch.replaceFirst(flow.getFeatureBranchPrefix(), "");
}
}
if (ctx.isInteractive())
{
List<String> possibleValues = new ArrayList<String>();
if (null == featureName)
{
featureName = "";
}
try
{
String rheadPrefix = Constants.R_HEADS + flow.getFeatureBranchPrefix();
String rOriginPrefix = JGitFlowConstants.R_REMOTE_ORIGIN + flow.getFeatureBranchPrefix();
List<Ref> branches = GitHelper.listBranchesWithPrefix(flow.git(), flow.getFeatureBranchPrefix(), flow.getReporter());
for (Ref branch : branches)
{
String simpleName = "";
if(branch.getName().contains(rheadPrefix))
{
simpleName = branch.getName().substring(branch.getName().indexOf(rheadPrefix) + rheadPrefix.length());
}
if(branch.getName().contains(rOriginPrefix))
{
simpleName = branch.getName().substring(branch.getName().indexOf(rOriginPrefix) + rOriginPrefix.length());
}
if(!Strings.isNullOrEmpty(simpleName) && !possibleValues.contains(simpleName))
{
possibleValues.add(simpleName);
}
}
featureName = promptForExistingFeatureName(flow.getFeatureBranchPrefix(), featureName, possibleValues);
}
catch (JGitFlowGitAPIException e)
{
throw new MavenJGitFlowException("Unable to determine feature names", e);
}
}
else
{
if (StringUtils.isBlank(featureName))
{
throw new MavenJGitFlowException("Missing featureName mojo option.");
}
}
return featureName;
}