Skip to content

Commit

Permalink
Closes #22 - Don't merge to the same branch when using single branch …
Browse files Browse the repository at this point in the history
…model like GitHub Flow, or tag, or fetch, or push.
  • Loading branch information
aleksandr-m committed Oct 6, 2016
1 parent 7636305 commit d55dc26
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,17 @@ protected String getCurrentProjectVersion() throws MojoFailureException {
}
}

/**
* Compares the production branch name with the development branch name.
*
* @return <code>true</code> if the production branch name is different from
* the development branch name, <code>false</code> otherwise.
*/
protected boolean notSameProdDevName() {
return !gitFlowConfig.getProductionBranch().equals(
gitFlowConfig.getDevelopmentBranch());
}

/**
* Checks uncommitted changes.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,10 @@ public void execute() throws MojoExecutionException, MojoFailureException {

// fetch and check remote
if (fetchRemote) {
gitFetchRemoteAndCompare(gitFlowConfig.getDevelopmentBranch());
if (notSameProdDevName()) {
gitFetchRemoteAndCompare(gitFlowConfig
.getDevelopmentBranch());
}
gitFetchRemoteAndCompare(gitFlowConfig.getProductionBranch());
}

Expand Down Expand Up @@ -147,11 +150,13 @@ public void execute() throws MojoExecutionException, MojoFailureException {
// git merge --no-ff hotfix/...
gitMergeNoff(hotfixBranchName);
} else {
// git checkout develop
gitCheckout(gitFlowConfig.getDevelopmentBranch());
if (notSameProdDevName()) {
// git checkout develop
gitCheckout(gitFlowConfig.getDevelopmentBranch());

// git merge --no-ff hotfix/...
gitMergeNoff(hotfixBranchName);
// git merge --no-ff hotfix/...
gitMergeNoff(hotfixBranchName);
}

// get current project version from pom
final String currentVersion = getCurrentProjectVersion();
Expand Down Expand Up @@ -195,7 +200,7 @@ public void execute() throws MojoExecutionException, MojoFailureException {
gitPush(gitFlowConfig.getProductionBranch(), !skipTag);

// if no release branch
if (StringUtils.isBlank(releaseBranch)) {
if (StringUtils.isBlank(releaseBranch) && notSameProdDevName()) {
gitPush(gitFlowConfig.getDevelopmentBranch(), !skipTag);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,10 @@ public void execute() throws MojoExecutionException, MojoFailureException {

// fetch and check remote
if (fetchRemote) {
gitFetchRemoteAndCompare(gitFlowConfig.getDevelopmentBranch());
if (notSameProdDevName()) {
gitFetchRemoteAndCompare(gitFlowConfig
.getDevelopmentBranch());
}
gitFetchRemoteAndCompare(gitFlowConfig.getProductionBranch());
}

Expand Down Expand Up @@ -126,10 +129,12 @@ public void execute() throws MojoExecutionException, MojoFailureException {
commitMessages.getTagReleaseMessage());
}

// git checkout develop
gitCheckout(gitFlowConfig.getDevelopmentBranch());
if (notSameProdDevName()) {
// git checkout develop
gitCheckout(gitFlowConfig.getDevelopmentBranch());

gitMerge(releaseBranch, releaseRebase, releaseMergeNoFF);
gitMerge(releaseBranch, releaseRebase, releaseMergeNoFF);
}

String nextSnapshotVersion = null;
// get next snapshot version
Expand Down Expand Up @@ -167,7 +172,9 @@ public void execute() throws MojoExecutionException, MojoFailureException {

if (pushRemote) {
gitPush(gitFlowConfig.getProductionBranch(), !skipTag);
gitPush(gitFlowConfig.getDevelopmentBranch(), !skipTag);
if (notSameProdDevName()) {
gitPush(gitFlowConfig.getDevelopmentBranch(), !skipTag);
}
}
} catch (CommandLineException e) {
getLog().error(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,10 @@ public void execute() throws MojoExecutionException, MojoFailureException {

// fetch and check remote
if (fetchRemote) {
gitFetchRemoteAndCompare(gitFlowConfig.getDevelopmentBranch());
if (notSameProdDevName()) {
gitFetchRemoteAndCompare(gitFlowConfig
.getDevelopmentBranch());
}
gitFetchRemoteAndCompare(gitFlowConfig.getProductionBranch());
}

Expand Down Expand Up @@ -151,11 +154,13 @@ public void execute() throws MojoExecutionException, MojoFailureException {
gitCommit(commitMessages.getReleaseStartMessage());
}

// git checkout master
gitCheckout(gitFlowConfig.getProductionBranch());
if (notSameProdDevName()) {
// git checkout master
gitCheckout(gitFlowConfig.getProductionBranch());

gitMerge(gitFlowConfig.getDevelopmentBranch(), releaseRebase,
releaseMergeNoFF);
gitMerge(gitFlowConfig.getDevelopmentBranch(), releaseRebase,
releaseMergeNoFF);
}

if (!skipTag) {
if (tychoBuild && ArtifactUtils.isSnapshot(version)) {
Expand All @@ -168,8 +173,10 @@ public void execute() throws MojoExecutionException, MojoFailureException {
commitMessages.getTagReleaseMessage());
}

// git checkout develop
gitCheckout(gitFlowConfig.getDevelopmentBranch());
if (notSameProdDevName()) {
// git checkout develop
gitCheckout(gitFlowConfig.getDevelopmentBranch());
}

String nextSnapshotVersion = null;
// get next snapshot version
Expand Down Expand Up @@ -202,7 +209,9 @@ public void execute() throws MojoExecutionException, MojoFailureException {

if (pushRemote) {
gitPush(gitFlowConfig.getProductionBranch(), !skipTag);
gitPush(gitFlowConfig.getDevelopmentBranch(), !skipTag);
if (notSameProdDevName()) {
gitPush(gitFlowConfig.getDevelopmentBranch(), !skipTag);
}
}
} catch (CommandLineException e) {
getLog().error(e);
Expand Down

0 comments on commit d55dc26

Please sign in to comment.