assertEquals(CherryPickStatus.CONFLICTING, result.getStatus());
assertTrue(new File(db.getDirectory(), Constants.MERGE_MSG).exists());
- assertEquals("side\n\nConflicts:\n\ta\n", db.readMergeCommitMsg());
+ assertEquals("side\n\n# Conflicts:\n#\ta\n",
+ db.readMergeCommitMsg());
assertTrue(new File(db.getDirectory(), Constants.CHERRY_PICK_HEAD)
.exists());
assertEquals(sideCommit.getId(), db.readCherryPickHead());
String expected = "<<<<<<< master\na(master)\n=======\na(side)\n>>>>>>> 527460a side\n";
assertEquals(expected, read("a"));
assertTrue(new File(db.getDirectory(), Constants.MERGE_MSG).exists());
- assertEquals("side\n\nConflicts:\n\ta\n", db.readMergeCommitMsg());
+ assertEquals("side\n\n# Conflicts:\n#\ta\n", db.readMergeCommitMsg());
assertFalse(new File(db.getDirectory(), Constants.CHERRY_PICK_HEAD)
.exists());
assertEquals(RepositoryState.SAFE, db.getRepositoryState());
git.merge().include(sideBranch)
.setStrategy(MergeStrategy.RESOLVE).call();
- assertEquals("Merge branch 'side'\n\nConflicts:\n\ta\n",
+ assertEquals("Merge branch 'side'\n\n# Conflicts:\n#\ta\n",
db.readMergeCommitMsg());
}
+ dateFormatter.formatDate(third
.getAuthorIdent()) + "\n\n\tthird commit\n",
db.readSquashCommitMsg());
- assertEquals("\nConflicts:\n\tfile2\n", db.readMergeCommitMsg());
+ assertEquals("\n# Conflicts:\n#\tfile2\n", db.readMergeCommitMsg());
Status stat = git.status().call();
assertEquals(Sets.of("file2"), stat.getConflicting());
git.merge().include(sideBranch).setStrategy(MergeStrategy.RESOLVE)
.setMessage("user message").call();
- assertEquals("user message\n\nConflicts:\n\ta\n",
+ assertEquals("user message\n\n# Conflicts:\n#\ta\n",
db.readMergeCommitMsg());
}
}
assertTrue(new File(db.getDirectory(), Constants.MERGE_MSG).exists());
assertEquals("Revert \"" + sideCommit.getShortMessage()
+ "\"\n\nThis reverts commit " + sideCommit.getId().getName()
- + ".\n\nConflicts:\n\ta\n",
+ + ".\n\n# Conflicts:\n#\ta\n",
db.readMergeCommitMsg());
assertTrue(new File(db.getDirectory(), Constants.REVERT_HEAD)
.exists());
import java.io.IOException;
import java.util.Arrays;
+import java.util.List;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.ObjectIdRef;
public void testFormatWithConflictsNoFooter() {
String originalMessage = "Header Line\n\nCommit body\n";
String message = formatter.formatWithConflicts(originalMessage,
- Arrays.asList(new String[] { "path1" }));
- assertEquals("Header Line\n\nCommit body\n\nConflicts:\n\tpath1\n",
+ List.of("path1"), '#');
+ assertEquals("Header Line\n\nCommit body\n\n# Conflicts:\n#\tpath1\n",
message);
}
public void testFormatWithConflictsNoFooterNoLineBreak() {
String originalMessage = "Header Line\n\nCommit body";
String message = formatter.formatWithConflicts(originalMessage,
- Arrays.asList(new String[] { "path1" }));
- assertEquals("Header Line\n\nCommit body\n\nConflicts:\n\tpath1\n",
+ List.of("path1"), '#');
+ assertEquals("Header Line\n\nCommit body\n\n# Conflicts:\n#\tpath1\n",
+ message);
+ }
+
+ @Test
+ public void testFormatWithConflictsCustomCharacter() {
+ String originalMessage = "Header Line\n\nCommit body";
+ String message = formatter.formatWithConflicts(originalMessage,
+ List.of("path1"), ';');
+ assertEquals("Header Line\n\nCommit body\n\n; Conflicts:\n;\tpath1\n",
message);
}
String originalMessage = "Header Line\n\nCommit body\n\nChangeId:"
+ " I123456789123456789123456789123456789\nBug:1234567\n";
String message = formatter.formatWithConflicts(originalMessage,
- Arrays.asList(new String[] { "path1" }));
+ List.of("path1"), '#');
assertEquals(
- "Header Line\n\nCommit body\n\nConflicts:\n\tpath1\n\n"
+ "Header Line\n\nCommit body\n\n# Conflicts:\n#\tpath1\n\n"
+ "ChangeId: I123456789123456789123456789123456789\nBug:1234567\n",
message);
}
String originalMessage = "Header Line\n\nCommit body\nBug:1234567\nMore Body\n\nChangeId:"
+ " I123456789123456789123456789123456789\nBug:1234567\n";
String message = formatter.formatWithConflicts(originalMessage,
- Arrays.asList(new String[] { "path1" }));
+ List.of("path1"), '#');
assertEquals(
- "Header Line\n\nCommit body\nBug:1234567\nMore Body\n\nConflicts:\n\tpath1\n\n"
+ "Header Line\n\nCommit body\nBug:1234567\nMore Body\n\n# Conflicts:\n#\tpath1\n\n"
+ "ChangeId: I123456789123456789123456789123456789\nBug:1234567\n",
message);
}
if (unmergedPaths != null) {
message = new MergeMessageFormatter()
.formatWithConflicts(srcCommit.getFullMessage(),
- unmergedPaths);
+ unmergedPaths, '#');
} else {
message = srcCommit.getFullMessage();
}
failingPaths, null);
}
String mergeMessageWithConflicts = new MergeMessageFormatter()
- .formatWithConflicts(mergeMessage, unmergedPaths);
+ .formatWithConflicts(mergeMessage, unmergedPaths, '#');
repo.writeMergeCommitMsg(mergeMessageWithConflicts);
return new MergeResult(null, merger.getBaseCommitId(),
new ObjectId[] { headCommit.getId(),
merger.getMergeResults(), failingPaths, null);
if (!merger.failed() && !unmergedPaths.isEmpty()) {
String message = new MergeMessageFormatter()
- .formatWithConflicts(newMessage,
- merger.getUnmergedPaths());
+ .formatWithConflicts(newMessage,
+ merger.getUnmergedPaths(), '#');
repo.writeRevertHead(srcCommit.getId());
repo.writeMergeCommitMsg(message);
}
}
/**
- * Add section with conflicting paths to merge message.
+ * Add section with conflicting paths to merge message. Lines are prefixed
+ * with a hash.
*
* @param message
* the original merge message
* @param conflictingPaths
* the paths with conflicts
* @return merge message with conflicting paths added
+ * @deprecated since 6.1; use
+ * {@link #formatWithConflicts(String, Iterable, char)} instead
*/
+ @Deprecated
public String formatWithConflicts(String message,
List<String> conflictingPaths) {
+ return formatWithConflicts(message, conflictingPaths, '#');
+ }
+
+ /**
+ * Add section with conflicting paths to merge message.
+ *
+ * @param message
+ * the original merge message
+ * @param conflictingPaths
+ * the paths with conflicts
+ * @param commentChar
+ * comment character to use for prefixing the conflict lines
+ * @return merge message with conflicting paths added
+ * @since 6.1
+ */
+ public String formatWithConflicts(String message,
+ Iterable<String> conflictingPaths, char commentChar) {
StringBuilder sb = new StringBuilder();
String[] lines = message.split("\n"); //$NON-NLS-1$
int firstFooterLine = ChangeIdUtil.indexOfFirstFooterLine(lines);
- for (int i = 0; i < firstFooterLine; i++)
+ for (int i = 0; i < firstFooterLine; i++) {
sb.append(lines[i]).append('\n');
- if (firstFooterLine == lines.length && message.length() != 0)
+ }
+ if (firstFooterLine == lines.length && message.length() != 0) {
sb.append('\n');
- addConflictsMessage(conflictingPaths, sb);
- if (firstFooterLine < lines.length)
+ }
+ addConflictsMessage(conflictingPaths, sb, commentChar);
+ if (firstFooterLine < lines.length) {
sb.append('\n');
- for (int i = firstFooterLine; i < lines.length; i++)
+ }
+ for (int i = firstFooterLine; i < lines.length; i++) {
sb.append(lines[i]).append('\n');
+ }
return sb.toString();
}
- private static void addConflictsMessage(List<String> conflictingPaths,
- StringBuilder sb) {
- sb.append("Conflicts:\n"); //$NON-NLS-1$
+ private static void addConflictsMessage(Iterable<String> conflictingPaths,
+ StringBuilder sb, char commentChar) {
+ sb.append(commentChar).append(" Conflicts:\n"); //$NON-NLS-1$
for (String conflictingPath : conflictingPaths) {
- sb.append('\t').append(conflictingPath).append('\n');
+ sb.append(commentChar).append('\t').append(conflictingPath)
+ .append('\n');
}
}