Skip to content

Commit

Permalink
Closes #17 - Allow to squash feature commits
Browse files Browse the repository at this point in the history
  • Loading branch information
aleksandr-m committed Jun 2, 2016
1 parent bf14bc5 commit 2023c59
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,20 @@ protected void gitMergeNoff(final String branchName)
gitMerge(branchName, false, true);
}

/**
* Executes git merge --squash.
*
* @param branchName
* Branch name to merge.
* @throws MojoFailureException
* @throws CommandLineException
*/
protected void gitMergeSquash(final String branchName)
throws MojoFailureException, CommandLineException {
getLog().info("Squashing '" + branchName + "' branch.");
executeGitCommand("merge", "--squash", branchName);
}

/**
* Executes git tag -a -m.
*
Expand Down Expand Up @@ -457,6 +471,21 @@ protected void gitBranchDelete(final String branchName)
executeGitCommand("branch", "-d", branchName);
}

/**
* Executes git branch -D.
*
* @param branchName
* Branch name to delete.
* @throws MojoFailureException
* @throws CommandLineException
*/
protected void gitBranchDeleteForce(final String branchName)
throws MojoFailureException, CommandLineException {
getLog().info("Deleting (-D) '" + branchName + "' branch.");

executeGitCommand("branch", "-D", branchName);
}

/**
* Executes 'set' goal of versions-maven-plugin or 'set-version' of
* tycho-versions-plugin in case it is tycho build.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,15 @@ public class GitFlowFeatureFinishMojo extends AbstractGitFlowMojo {
@Parameter(property = "skipTestProject", defaultValue = "false")
private boolean skipTestProject = false;

/**
* Whether to squash feature branch commits into a single commit upon
* merging.
*
* @since 1.2.3
*/
@Parameter(property = "featureSquash", defaultValue = "false")
private boolean featureSquash = false;

/** {@inheritDoc} */
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
Expand Down Expand Up @@ -105,8 +114,14 @@ public void execute() throws MojoExecutionException, MojoFailureException {
// git checkout develop
gitCheckout(gitFlowConfig.getDevelopmentBranch());

// git merge --no-ff feature/...
gitMergeNoff(featureBranchName);
if (featureSquash) {
// git merge --squash feature/...
gitMergeSquash(featureBranchName);
gitCommit(featureBranchName);
} else {
// git merge --no-ff feature/...
gitMergeNoff(featureBranchName);
}

// get current project version from pom
final String currentVersion = getCurrentProjectVersion();
Expand All @@ -131,8 +146,13 @@ public void execute() throws MojoExecutionException, MojoFailureException {
}

if (!keepBranch) {
// git branch -d feature/...
gitBranchDelete(featureBranchName);
if (featureSquash) {
// git branch -D feature/...
gitBranchDeleteForce(featureBranchName);
} else {
// git branch -d feature/...
gitBranchDelete(featureBranchName);
}
}
} catch (CommandLineException e) {
getLog().error(e);
Expand Down

0 comments on commit 2023c59

Please sign in to comment.