Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds release-finish check for remotes #171

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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 <code>refname:short</code> format.
*
* @param branchName
* Branch name to find.
* @param firstMatch
* Return first match.
* @param includeRemote
* Include remote origin
* @return Branch names which matches <code>refs/heads/{branchName}*</code> and conditionally also
* <code>refs/remote/{origin}/{branchName}*</code>.
* @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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
Expand Down