diff --git a/src/main/java/com/amashchenko/maven/plugin/gitflow/AbstractGitFlowMojo.java b/src/main/java/com/amashchenko/maven/plugin/gitflow/AbstractGitFlowMojo.java
index 7e0ad030..970e4390 100644
--- a/src/main/java/com/amashchenko/maven/plugin/gitflow/AbstractGitFlowMojo.java
+++ b/src/main/java/com/amashchenko/maven/plugin/gitflow/AbstractGitFlowMojo.java
@@ -418,20 +418,44 @@ private void gitSetConfig(final String name, String value)
protected String gitFindBranches(final String branchName,
final boolean firstMatch) throws MojoFailureException,
CommandLineException {
+
+ return gitFindBranches(branchName, firstMatch, false);
+ }
+
+ /**
+ * Executes git for-each-ref with refname:short
format.
+ *
+ * @param branchName
+ * Branch name to find.
+ * @param firstMatch
+ * Return first match.
+ * @param includeRemote
+ * Include remote origin
+ * @return Branch names which matches refs/heads/{branchName}*
and conditionally also
+ * refs/remote/{origin}/{branchName}*
.
+ * @throws MojoFailureException
+ * @throws CommandLineException
+ */
+ protected String gitFindBranches(final String branchName,
+ final boolean firstMatch, final boolean includeRemote) throws MojoFailureException,
+ CommandLineException {
String wildcard = "*";
if (branchName.endsWith("/")) {
wildcard = "**";
}
+ String pattern = "refs/heads/" + branchName + wildcard;
+ if (includeRemote) {
+ pattern = pattern + " refs/remotes/" + gitFlowConfig.getOrigin() + "/" + branchName + wildcard;
+ }
+
String branches;
if (firstMatch) {
branches = executeGitCommandReturn("for-each-ref", "--count=1",
- "--format=\"%(refname:short)\"", "refs/heads/" + branchName
- + wildcard);
+ "--format=\"%(refname:short)\"", pattern);
} else {
branches = executeGitCommandReturn("for-each-ref",
- "--format=\"%(refname:short)\"", "refs/heads/" + branchName
- + wildcard);
+ "--format=\"%(refname:short)\"", pattern);
}
// on *nix systems return values from git for-each-ref are wrapped in
diff --git a/src/main/java/com/amashchenko/maven/plugin/gitflow/GitFlowReleaseFinishMojo.java b/src/main/java/com/amashchenko/maven/plugin/gitflow/GitFlowReleaseFinishMojo.java
index d389a7d2..74247c9c 100644
--- a/src/main/java/com/amashchenko/maven/plugin/gitflow/GitFlowReleaseFinishMojo.java
+++ b/src/main/java/com/amashchenko/maven/plugin/gitflow/GitFlowReleaseFinishMojo.java
@@ -168,9 +168,9 @@ public void execute() throws MojoExecutionException, MojoFailureException {
// check uncommitted changes
checkUncommittedChanges();
- // git for-each-ref --format='%(refname:short)' refs/heads/release/*
+ // git for-each-ref --format='%(refname:short)' refs/heads/release/* refs/remotes/{origin}/release/*
final String releaseBranch = gitFindBranches(
- gitFlowConfig.getReleaseBranchPrefix(), false).trim();
+ gitFlowConfig.getReleaseBranchPrefix(), false, true).trim();
if (StringUtils.isBlank(releaseBranch)) {
throw new MojoFailureException("There is no release branch.");