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

Hotfix Finish support without parameter hotfixBranch #327

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
7 changes: 7 additions & 0 deletions src/it/hotfix-finish-6-it/expected-development-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>
7 changes: 7 additions & 0 deletions src/it/hotfix-finish-6-it/expected-production-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</version>
</project>
6 changes: 6 additions & 0 deletions src/it/hotfix-finish-6-it/gitignorefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
build.log
expected-development-pom.xml
expected-production-pom.xml
invoker.properties
init.bsh
verify.bsh
41 changes: 41 additions & 0 deletions src/it/hotfix-finish-6-it/init.bsh
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import org.codehaus.plexus.util.FileUtils;

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 '[email protected]'");
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 + " checkout -b develop");
p.waitFor();

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

File pomfile = new File(basedir, "pom.xml");
String pomfilestr = FileUtils.fileRead(pomfile, "UTF-8");
pomfilestr = pomfilestr.replaceAll("0.0.3", "0.0.4");
FileUtils.fileWrite(basedir + "/pom.xml", "UTF-8", pomfilestr);

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 next");
p.waitFor();

} catch (Exception e) {
e.printStackTrace();
return false;
}
return true;
3 changes: 3 additions & 0 deletions src/it/hotfix-finish-6-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}:hotfix-finish -DpushRemote=false -B

invoker.description=Non-interactive hotfix-finish without using hotfixBranch parameter.
7 changes: 7 additions & 0 deletions src/it/hotfix-finish-6-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</version>
</project>
38 changes: 38 additions & 0 deletions src/it/hotfix-finish-6-it/verify.bsh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import org.codehaus.plexus.util.FileUtils;

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

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

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

if (!expected.equals(actual)) {
System.out.println("hotfix-finish expected: " + expected + " actual was:" + actual);
return false;
}

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

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

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

if (!expected.equals(actual)) {
System.out.println("hotfix-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 @@ -154,6 +154,31 @@ public void execute() throws MojoExecutionException, MojoFailureException {
throw new MojoFailureException("Hotfix branch with name '" + branch + "' doesn't exist. Cannot finish hotfix.");
}
hotfixBranchName = branch;
} else if (StringUtils.isBlank(hotfixVersion)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DISCLAIMER: I'm not a maintainer, so feel free to ignore what I'm saying. 😉

This is basically the same block as in GitFlowReleaseFinishMojo.

I wonder if it makes sense / is possible to avoid the duplicated code by, e.g., having an intermediate layer like AbstractGitFlowFinishMojo, which encloses this functionality. (Although it looks like GitFlowFeatureFinishMojo couldn't benefit from it.)

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Abstraction via inheritance is an obvious improvement since you write less code, right? But in many cases inheritance becomes much more inconvenient to maintain, than just copy some code, that has potential to diverge a little in the future.

If any, I would prefer using composition over inheritance everywhere. At least you can interchange the solution with a very less effort.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Abstraction via inheritance is an obvious improvement since you write less code, right?

No, but thanks for ELI5. 😉

// git for-each-ref --format='%(refname:short)' refs/heads/hotfix/*
hotfixBranchName = gitFindBranches(gitFlowConfig.getHotfixBranchPrefix(), false).trim();

if (StringUtils.isBlank(hotfixBranchName)) {
if (fetchRemote) {
hotfixBranchName = gitFetchAndFindRemoteBranches(gitFlowConfig.getOrigin(),
gitFlowConfig.getHotfixBranchPrefix(), false).trim();
if (StringUtils.isBlank(hotfixBranchName)) {
throw new MojoFailureException("There is no remote or local hotfix branch.");
}

// remove remote name with slash from branch name
hotfixBranchName = hotfixBranchName.substring(gitFlowConfig.getOrigin().length() + 1);

gitCreateAndCheckout(hotfixBranchName, gitFlowConfig.getOrigin() + "/" + hotfixBranchName);
} else {
throw new MojoFailureException("There is no hotfix branch.");
}
}

if (StringUtils.countMatches(hotfixBranchName, gitFlowConfig.getHotfixBranchPrefix()) > 1) {
throw new MojoFailureException(
"More than one remote hotfix branch exists. Cannot finish hotfix. Define branch name to finish hotfix.");
}
}

if (StringUtils.isBlank(hotfixBranchName)) {
Expand Down