Skip to content

Commit af7a8a1

Browse files
committed
Add ability to skip merging release into production branch - closes #74
1 parent 717be90 commit af7a8a1

File tree

11 files changed

+169
-8
lines changed

11 files changed

+169
-8
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
2+
<modelVersion>4.0.0</modelVersion>
3+
<groupId>com.amashchenko.maven.plugin</groupId>
4+
<artifactId>gitflow-maven-test</artifactId>
5+
<packaging>pom</packaging>
6+
<version>0.0.4-SNAPSHOT</version>
7+
</project>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
2+
<modelVersion>4.0.0</modelVersion>
3+
<groupId>com.amashchenko.maven.plugin</groupId>
4+
<artifactId>gitflow-maven-test</artifactId>
5+
<packaging>pom</packaging>
6+
<version>0.0.1</version>
7+
</project>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
build.log
2+
expected-development-pom.xml
3+
expected-production-pom.xml
4+
invoker.properties
5+
init.bsh
6+
verify.bsh
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import org.codehaus.plexus.util.FileUtils;
2+
3+
try {
4+
new File(basedir, "gitignorefile").renameTo(new File(basedir, ".gitignore"));
5+
6+
Process p = Runtime.getRuntime().exec("git --git-dir=" + basedir + "/.git --work-tree=" + basedir + " init");
7+
p.waitFor();
8+
9+
Process p = Runtime.getRuntime().exec("git --git-dir=" + basedir + "/.git --work-tree=" + basedir + " config user.email '[email protected]'");
10+
p.waitFor();
11+
Process p = Runtime.getRuntime().exec("git --git-dir=" + basedir + "/.git --work-tree=" + basedir + " config user.name 'a'");
12+
p.waitFor();
13+
14+
p = Runtime.getRuntime().exec("git --git-dir=" + basedir + "/.git --work-tree=" + basedir + " add .");
15+
p.waitFor();
16+
17+
p = Runtime.getRuntime().exec("git --git-dir=" + basedir + "/.git --work-tree=" + basedir + " commit -m init");
18+
p.waitFor();
19+
20+
p = Runtime.getRuntime().exec("git --git-dir=" + basedir + "/.git --work-tree=" + basedir + " branch develop");
21+
p.waitFor();
22+
23+
p = Runtime.getRuntime().exec("git --git-dir=" + basedir + "/.git --work-tree=" + basedir + " checkout -b release/0.0.3");
24+
p.waitFor();
25+
26+
File pomfile = new File(basedir, "pom.xml");
27+
String pomfilestr = FileUtils.fileRead(pomfile, "UTF-8");
28+
pomfilestr = pomfilestr.replaceAll("0.0.1", "0.0.3");
29+
FileUtils.fileWrite(basedir + "/pom.xml", "UTF-8", pomfilestr);
30+
31+
p = Runtime.getRuntime().exec("git --git-dir=" + basedir + "/.git --work-tree=" + basedir + " add .");
32+
p.waitFor();
33+
34+
p = Runtime.getRuntime().exec("git --git-dir=" + basedir + "/.git --work-tree=" + basedir + " commit -m 0.0.3");
35+
p.waitFor();
36+
37+
} catch (Exception e) {
38+
e.printStackTrace();
39+
return false;
40+
}
41+
return true;
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
invoker.goals=${project.groupId}:${project.artifactId}:${project.version}:release-finish -DpushRemote=false -DskipReleaseMergeProdBranch
2+
3+
invoker.description=Test release-finish with skipReleaseMergeProdBranch parameter.

src/it/release-finish-7-it/pom.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
2+
<modelVersion>4.0.0</modelVersion>
3+
<groupId>com.amashchenko.maven.plugin</groupId>
4+
<artifactId>gitflow-maven-test</artifactId>
5+
<packaging>pom</packaging>
6+
<version>0.0.1</version>
7+
</project>
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import org.codehaus.plexus.util.FileUtils;
2+
3+
try {
4+
File gitTag = new File(basedir, ".git/refs/tags/0.0.3");
5+
if (!gitTag.exists()) {
6+
System.out.println("release-finish .git/refs/tags/0.0.3 doesn't exist");
7+
return false;
8+
}
9+
10+
File gitReleaseRef = new File(basedir, ".git/refs/heads/release/0.0.3");
11+
if (gitReleaseRef.exists()) {
12+
System.out.println("release-finish .git/refs/heads/release/0.0.3 exists");
13+
return false;
14+
}
15+
File gitDevelopRef = new File(basedir, ".git/refs/heads/develop");
16+
if (!gitDevelopRef.exists()) {
17+
System.out.println("release-finish .git/refs/heads/develop doesn't exist");
18+
return false;
19+
}
20+
File gitMasterRef = new File(basedir, ".git/refs/heads/master");
21+
if (!gitMasterRef.exists()) {
22+
System.out.println("release-finish .git/refs/heads/master doesn't exist");
23+
return false;
24+
}
25+
26+
File file = new File(basedir, "pom.xml");
27+
File expectedFile = new File(basedir, "expected-development-pom.xml");
28+
29+
String actual = FileUtils.fileRead(file, "UTF-8");
30+
String expected = FileUtils.fileRead(expectedFile, "UTF-8");
31+
32+
actual = actual.replaceAll("\\r?\\n", "");
33+
expected = expected.replaceAll("\\r?\\n", "");
34+
35+
if (!expected.equals(actual)) {
36+
System.out.println("release-finish expected development pom: " + expected + " actual was:" + actual);
37+
return false;
38+
}
39+
40+
p = Runtime.getRuntime().exec("git --git-dir=" + basedir + "/.git --work-tree=" + basedir + " checkout master");
41+
p.waitFor();
42+
43+
file = new File(basedir, "pom.xml");
44+
expectedFile = new File(basedir, "expected-production-pom.xml");
45+
46+
actual = FileUtils.fileRead(file, "UTF-8");
47+
expected = FileUtils.fileRead(expectedFile, "UTF-8");
48+
49+
actual = actual.replaceAll("\\r?\\n", "");
50+
expected = expected.replaceAll("\\r?\\n", "");
51+
52+
if (!expected.equals(actual)) {
53+
System.out.println("release-finish expected production pom: " + expected + " actual was:" + actual);
54+
return false;
55+
}
56+
57+
} catch (Exception e) {
58+
e.printStackTrace();
59+
return false;
60+
}
61+
return true;

src/it/release-finish-it/init.bsh

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import org.codehaus.plexus.util.FileUtils;
2+
13
try {
24
new File(basedir, "gitignorefile").renameTo(new File(basedir, ".gitignore"));
35

@@ -15,10 +17,21 @@ try {
1517
p = Runtime.getRuntime().exec("git --git-dir=" + basedir + "/.git --work-tree=" + basedir + " commit -m init");
1618
p.waitFor();
1719

18-
p = Runtime.getRuntime().exec("git --git-dir=" + basedir + "/.git --work-tree=" + basedir + " branch release/0.0.3");
20+
p = Runtime.getRuntime().exec("git --git-dir=" + basedir + "/.git --work-tree=" + basedir + " branch develop");
21+
p.waitFor();
22+
23+
p = Runtime.getRuntime().exec("git --git-dir=" + basedir + "/.git --work-tree=" + basedir + " checkout -b release/0.0.3");
24+
p.waitFor();
25+
26+
File pomfile = new File(basedir, "pom.xml");
27+
String pomfilestr = FileUtils.fileRead(pomfile, "UTF-8");
28+
pomfilestr = pomfilestr.replaceAll("0.0.1", "0.0.3");
29+
FileUtils.fileWrite(basedir + "/pom.xml", "UTF-8", pomfilestr);
30+
31+
p = Runtime.getRuntime().exec("git --git-dir=" + basedir + "/.git --work-tree=" + basedir + " add .");
1932
p.waitFor();
2033

21-
p = Runtime.getRuntime().exec("git --git-dir=" + basedir + "/.git --work-tree=" + basedir + " checkout -b develop");
34+
p = Runtime.getRuntime().exec("git --git-dir=" + basedir + "/.git --work-tree=" + basedir + " commit -m 0.0.3");
2235
p.waitFor();
2336

2437
} catch (Exception e) {

src/it/release-finish-it/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
<groupId>com.amashchenko.maven.plugin</groupId>
44
<artifactId>gitflow-maven-test</artifactId>
55
<packaging>pom</packaging>
6-
<version>0.0.3</version>
6+
<version>0.0.1</version>
77
</project>

src/main/java/com/amashchenko/maven/plugin/gitflow/GitFlowReleaseFinishMojo.java

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,13 @@ public class GitFlowReleaseFinishMojo extends AbstractGitFlowMojo {
159159
@Parameter(property = "useSnapshotInRelease", defaultValue = "false")
160160
private boolean useSnapshotInRelease;
161161

162+
/**
163+
* Whether to skip merging release into the production branch.
164+
*
165+
*/
166+
@Parameter(property = "skipReleaseMergeProdBranch", defaultValue = "false")
167+
private boolean skipReleaseMergeProdBranch = false;
168+
162169
/** {@inheritDoc} */
163170
@Override
164171
public void execute() throws MojoExecutionException, MojoFailureException {
@@ -252,11 +259,13 @@ public void execute() throws MojoExecutionException, MojoFailureException {
252259
gitCommit(commitMessages.getReleaseFinishMessage(), messageProperties);
253260
}
254261

255-
// git checkout master
256-
gitCheckout(gitFlowConfig.getProductionBranch());
262+
if (!skipReleaseMergeProdBranch) {
263+
// git checkout master
264+
gitCheckout(gitFlowConfig.getProductionBranch());
257265

258-
gitMerge(releaseBranch, releaseRebase, releaseMergeNoFF, releaseMergeFFOnly,
259-
commitMessages.getReleaseFinishMergeMessage(), messageProperties);
266+
gitMerge(releaseBranch, releaseRebase, releaseMergeNoFF, releaseMergeFFOnly, commitMessages.getReleaseFinishMergeMessage(),
267+
messageProperties);
268+
}
260269

261270
// get current project version from pom
262271
final String currentVersion = getCurrentProjectVersion();

0 commit comments

Comments
 (0)