aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit/src
diff options
context:
space:
mode:
authorThomas Wolf <thomas.wolf@paranor.ch>2022-01-16 15:50:00 +0100
committerThomas Wolf <thomas.wolf@paranor.ch>2022-01-31 00:42:35 +0100
commit1fd15e40cc7bf67c30849abc3030de8568246a4e (patch)
tree460bd4e5064a310cae1032073a7e6fbe0a0ee4c7 /org.eclipse.jgit/src
parente297f503a1674a699969ed61a982c8474f0a23da (diff)
downloadjgit-1fd15e40cc7bf67c30849abc3030de8568246a4e.tar.gz
jgit-1fd15e40cc7bf67c30849abc3030de8568246a4e.zip
Merge conflict messages: prefix conflict lines with a hash
C git also does so. Note that currently the comment character is hard-coded as the hash '#' throughout JGit. Bug: 548529 Change-Id: I4a5597694082a9e5b07412b365cfaf41fa034cfa Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
Diffstat (limited to 'org.eclipse.jgit/src')
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/api/CherryPickCommand.java2
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/api/MergeCommand.java2
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/api/RevertCommand.java4
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/merge/MergeMessageFormatter.java46
4 files changed, 40 insertions, 14 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/CherryPickCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/CherryPickCommand.java
index 7922f9e729..8ee1e965e9 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/api/CherryPickCommand.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/CherryPickCommand.java
@@ -183,7 +183,7 @@ public class CherryPickCommand extends GitCommand<CherryPickResult> {
if (unmergedPaths != null) {
message = new MergeMessageFormatter()
.formatWithConflicts(srcCommit.getFullMessage(),
- unmergedPaths);
+ unmergedPaths, '#');
} else {
message = srcCommit.getFullMessage();
}
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/MergeCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/MergeCommand.java
index ef56d802c8..ce068b6306 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/api/MergeCommand.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/MergeCommand.java
@@ -405,7 +405,7 @@ public class MergeCommand extends GitCommand<MergeResult> {
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(),
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/RevertCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/RevertCommand.java
index 22ef4d0a32..02f581cbb6 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/api/RevertCommand.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/RevertCommand.java
@@ -183,8 +183,8 @@ public class RevertCommand extends GitCommand<RevCommit> {
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);
}
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/merge/MergeMessageFormatter.java b/org.eclipse.jgit/src/org/eclipse/jgit/merge/MergeMessageFormatter.java
index f7966a267f..e0c083f55c 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/merge/MergeMessageFormatter.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/merge/MergeMessageFormatter.java
@@ -92,36 +92,62 @@ public class MergeMessageFormatter {
}
/**
- * 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');
}
}