Skip to content

Commit

Permalink
Fix wrong incrementing of feature name - fixes #288
Browse files Browse the repository at this point in the history
  • Loading branch information
aleksandr-m committed Mar 21, 2021
1 parent c2d640f commit d5a695a
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 2 deletions.
7 changes: 7 additions & 0 deletions src/it/feature-finish-3-it/expected-pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<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">
<modelVersion>4.0.0</modelVersion>
<groupId>com.amashchenko.maven.plugin</groupId>
<artifactId>gitflow-maven-test</artifactId>
<packaging>pom</packaging>
<version>0.0.4-SNAPSHOT</version>
</project>
5 changes: 5 additions & 0 deletions src/it/feature-finish-3-it/gitignorefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
build.log
expected-pom.xml
invoker.properties
init.bsh
verify.bsh
28 changes: 28 additions & 0 deletions src/it/feature-finish-3-it/init.bsh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
try {
new File(basedir, "gitignorefile").renameTo(new File(basedir, ".gitignore"));

Process p = Runtime.getRuntime().exec("git --git-dir=" + basedir + "/.git --work-tree=" + basedir + " init");
p.waitFor();

Process p = Runtime.getRuntime().exec("git --git-dir=" + basedir + "/.git --work-tree=" + basedir + " config user.email 'a@a.aa'");
p.waitFor();
Process p = Runtime.getRuntime().exec("git --git-dir=" + basedir + "/.git --work-tree=" + basedir + " config user.name 'a'");
p.waitFor();

p = Runtime.getRuntime().exec("git --git-dir=" + basedir + "/.git --work-tree=" + basedir + " add .");
p.waitFor();

p = Runtime.getRuntime().exec("git --git-dir=" + basedir + "/.git --work-tree=" + basedir + " commit -m init");
p.waitFor();

p = Runtime.getRuntime().exec("git --git-dir=" + basedir + "/.git --work-tree=" + basedir + " branch feature/ISSUE-288");
p.waitFor();

p = Runtime.getRuntime().exec("git --git-dir=" + basedir + "/.git --work-tree=" + basedir + " checkout -b develop");
p.waitFor();

} catch (Exception e) {
e.printStackTrace();
return false;
}
return true;
3 changes: 3 additions & 0 deletions src/it/feature-finish-3-it/invoker.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
invoker.goals=${project.groupId}:${project.artifactId}:${project.version}:feature-finish -DpushRemote=false -B -DfeatureName=ISSUE-288 -DincrementVersionAtFinish

invoker.description=Non-interactive feature-finish with incrementVersionAtFinish parameter.
7 changes: 7 additions & 0 deletions src/it/feature-finish-3-it/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<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">
<modelVersion>4.0.0</modelVersion>
<groupId>com.amashchenko.maven.plugin</groupId>
<artifactId>gitflow-maven-test</artifactId>
<packaging>pom</packaging>
<version>0.0.3-ISSUE-288-SNAPSHOT</version>
</project>
27 changes: 27 additions & 0 deletions src/it/feature-finish-3-it/verify.bsh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import org.codehaus.plexus.util.FileUtils;

try {
File gitRef = new File(basedir, ".git/refs/heads/feature/ISSUE-288");
if (gitRef.exists()) {
System.out.println("feature-finish .git/refs/heads/feature/ISSUE-288 exists");
return false;
}

File file = new File(basedir, "pom.xml");
File expectedFile = new File(basedir, "expected-pom.xml");

String actual = FileUtils.fileRead(file, "UTF-8");
String expected = FileUtils.fileRead(expectedFile, "UTF-8");

actual = actual.replaceAll("\\r?\\n", "");
expected = expected.replaceAll("\\r?\\n", "");

if (!expected.equals(actual)) {
System.out.println("feature-finish expected: " + expected + " actual was:" + actual);
return false;
}
} catch (Exception e) {
e.printStackTrace();
return false;
}
return true;
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,12 @@ public void execute() throws MojoExecutionException, MojoFailureException {
final String featName = featureBranchName.replaceFirst(gitFlowConfig.getFeatureBranchPrefix(), "");

if (incrementVersionAtFinish) {
GitFlowVersionInfo developVersionInfo = new GitFlowVersionInfo(featureVersion);
featureVersion = developVersionInfo.nextSnapshotVersion();
// prevent incrementing feature name which can hold numbers
String ver = featureVersion.replaceFirst("-" + featName, "");
GitFlowVersionInfo nextVersionInfo = new GitFlowVersionInfo(ver);
ver = nextVersionInfo.nextSnapshotVersion();
GitFlowVersionInfo featureVersionInfo = new GitFlowVersionInfo(ver);
featureVersion = featureVersionInfo.featureVersion(featName);

mvnSetVersions(featureVersion);

Expand Down

0 comments on commit d5a695a

Please sign in to comment.