diff --git a/src/it/hotfix-finish-6-it/expected-development-pom.xml b/src/it/hotfix-finish-6-it/expected-development-pom.xml new file mode 100644 index 00000000..b39a586f --- /dev/null +++ b/src/it/hotfix-finish-6-it/expected-development-pom.xml @@ -0,0 +1,7 @@ + + 4.0.0 + com.amashchenko.maven.plugin + gitflow-maven-test + pom + 0.0.4-SNAPSHOT + diff --git a/src/it/hotfix-finish-6-it/expected-production-pom.xml b/src/it/hotfix-finish-6-it/expected-production-pom.xml new file mode 100644 index 00000000..a4a4fe6f --- /dev/null +++ b/src/it/hotfix-finish-6-it/expected-production-pom.xml @@ -0,0 +1,7 @@ + + 4.0.0 + com.amashchenko.maven.plugin + gitflow-maven-test + pom + 0.0.4 + diff --git a/src/it/hotfix-finish-6-it/gitignorefile b/src/it/hotfix-finish-6-it/gitignorefile new file mode 100644 index 00000000..3f0b6969 --- /dev/null +++ b/src/it/hotfix-finish-6-it/gitignorefile @@ -0,0 +1,6 @@ +build.log +expected-development-pom.xml +expected-production-pom.xml +invoker.properties +init.bsh +verify.bsh diff --git a/src/it/hotfix-finish-6-it/init.bsh b/src/it/hotfix-finish-6-it/init.bsh new file mode 100644 index 00000000..c5e215e4 --- /dev/null +++ b/src/it/hotfix-finish-6-it/init.bsh @@ -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 '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 + " 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; diff --git a/src/it/hotfix-finish-6-it/invoker.properties b/src/it/hotfix-finish-6-it/invoker.properties new file mode 100644 index 00000000..5ae182dd --- /dev/null +++ b/src/it/hotfix-finish-6-it/invoker.properties @@ -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. diff --git a/src/it/hotfix-finish-6-it/pom.xml b/src/it/hotfix-finish-6-it/pom.xml new file mode 100644 index 00000000..b8bb10f1 --- /dev/null +++ b/src/it/hotfix-finish-6-it/pom.xml @@ -0,0 +1,7 @@ + + 4.0.0 + com.amashchenko.maven.plugin + gitflow-maven-test + pom + 0.0.3 + diff --git a/src/it/hotfix-finish-6-it/verify.bsh b/src/it/hotfix-finish-6-it/verify.bsh new file mode 100644 index 00000000..49e5d064 --- /dev/null +++ b/src/it/hotfix-finish-6-it/verify.bsh @@ -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; diff --git a/src/main/java/com/amashchenko/maven/plugin/gitflow/GitFlowHotfixFinishMojo.java b/src/main/java/com/amashchenko/maven/plugin/gitflow/GitFlowHotfixFinishMojo.java index 4553409e..78876285 100644 --- a/src/main/java/com/amashchenko/maven/plugin/gitflow/GitFlowHotfixFinishMojo.java +++ b/src/main/java/com/amashchenko/maven/plugin/gitflow/GitFlowHotfixFinishMojo.java @@ -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)) { + // 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)) {