Skip to content

Commit

Permalink
Merge pull request #9 from cecom/fix-merge-unrelated-histories
Browse files Browse the repository at this point in the history
Fix merge unrelated histories
  • Loading branch information
cecom authored Jul 20, 2017
2 parents cb35377 + 5d7c27a commit 5941b87
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>de.oppermann.pomutils</groupId>
<artifactId>pomutils</artifactId>
<version>1.4</version>
<version>develop</version>

<licenses>
<license>
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/de/oppermann/pomutils/util/POM.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,18 @@ public POM(String pomFileAsString) throws IOException, XMLStreamException {
throw new IllegalArgumentException("File [" + pomFile.getAbsolutePath() + "] not found.");
}

if (pomFile.length() == 0L) {
/*
* If we use git merge --allow-unrelated-histories, the base pom file
* can be empty, so it cannot be parsed
*/
rawModel = null;
projectIdentifier = null;
projectVersion = "";
parentVersion = "";
return;
}

initialize();
}

Expand Down
24 changes: 24 additions & 0 deletions src/test/java/de/oppermann/pomutils/PomMergeDriverTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -209,4 +209,28 @@ public void testAutoMergeFailed() throws Exception {

assertEquals("same version now", ourProjectVersion, theirPom.getProjectVersion());
}

public void testAutoMergeWithNoBaseCommit() throws Exception {
String myTestSubFolder = "merge/autoMergeSucceded_noConflict_their";

TestUtils.prepareTestFolder(myTestSubFolder);

String basePomFile = TestUtils.resourceBaseTestFolder + "/" + myTestSubFolder + "/base.pom.xml";
String ourPomFile = TestUtils.resourceBaseTestFolder + "/" + myTestSubFolder + "/our.pom.xml";
String theirPomFile = TestUtils.resourceBaseTestFolder + "/" + myTestSubFolder + "/their.pom.xml";

Ruleset ruleset = new Ruleset(SelectionStrategy.THEIR);

PomMergeDriver pomMergeDriver = new PomMergeDriver(ruleset, basePomFile, ourPomFile, theirPomFile);
int mergeReturnValue = pomMergeDriver.merge();

assertTrue("merge succeeded", mergeReturnValue == 0);

POM theirPom = new POM(theirPomFile);
POM ourPom = new POM(ourPomFile);

assertEquals("their", ourPom.getProjectVersion());
assertEquals("their", theirPom.getProjectVersion());
}

}
Empty file.
14 changes: 14 additions & 0 deletions src/test/resources/merge/autoMergeWithNoBaseCommit/our.pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>de.oppermann.git.pommergedriver</groupId>
<artifactId>pommergedriver</artifactId>
<version>our</version>
<dependencies>
<dependency>
<groupId>org.codehaus.mojo</groupId>
<artifactId>versions-maven-plugin</artifactId>
<version>2.5</version>
<type>maven-plugin</type>
</dependency>
</dependencies>
</project>
14 changes: 14 additions & 0 deletions src/test/resources/merge/autoMergeWithNoBaseCommit/their.pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>de.oppermann.git.pommergedriver</groupId>
<artifactId>pommergedriver</artifactId>
<version>their</version>
<dependencies>
<dependency>
<groupId>org.codehaus.mojo</groupId>
<artifactId>versions-maven-plugin</artifactId>
<version>2.5</version>
<type>maven-plugin</type>
</dependency>
</dependencies>
</project>

0 comments on commit 5941b87

Please sign in to comment.