PatchApplier: Set a boolean on the result if conflict markers were added

This will let callers show a different error message or mark the
state as conflicting.

Change-Id: Id8eea614b6b8d54c62b49ffbac90599e6f4c5efa
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/patch/PatchApplierTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/patch/PatchApplierTest.java
index 8f3478d..eec403a 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/patch/PatchApplierTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/patch/PatchApplierTest.java
@@ -376,7 +376,7 @@ public void testConflictMarkers() throws Exception {
 			error.hh = null; // We don't assert the hunk header as it is a
 								// complex object with lots of internal state.
 			assertEquals(error, new PatchApplier.Result.Error(
-					"cannot apply hunk", "allowconflict", null));
+					"cannot apply hunk", "allowconflict", null, true));
 			verifyChange(result, "allowconflict", true, 1);
 		}
 
@@ -391,7 +391,7 @@ public void testConflictMarkersOutOfBounds() throws Exception {
 			error.hh = null; // We don't assert the hunk header as it is a
 								// complex object with lots of internal state.
 			assertEquals(error, new PatchApplier.Result.Error(
-					"cannot apply hunk", "ConflictOutOfBounds", null));
+					"cannot apply hunk", "ConflictOutOfBounds", null, true));
 			verifyChange(result, "ConflictOutOfBounds", true, 1);
 		}
 
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/patch/PatchApplier.java b/org.eclipse.jgit/src/org/eclipse/jgit/patch/PatchApplier.java
index 84c2ec4..1a98d79 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/patch/PatchApplier.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/patch/PatchApplier.java
@@ -184,10 +184,27 @@ public static class Error {
 			@Nullable
 			HunkHeader hh;
 
-			Error(String msg, String oldFileName, @Nullable HunkHeader hh) {
+			final boolean isGitConflict;
+
+			Error(String msg, String oldFileName, @Nullable HunkHeader hh,
+					boolean isGitConflict) {
 				this.msg = msg;
 				this.oldFileName = oldFileName;
 				this.hh = hh;
+				this.isGitConflict = isGitConflict;
+			}
+
+			/**
+			 * Signals if as part of encountering this error, conflict markers
+			 * were added to the file.
+			 *
+			 * @return {@code true} if conflict markers were added for this
+			 *         error.
+			 *
+			 * @since 6.10
+			 */
+			public boolean isGitConflict() {
+				return isGitConflict;
 			}
 
 			@Override
@@ -213,12 +230,14 @@ public boolean equals(Object o) {
 				Error error = (Error) o;
 				return Objects.equals(msg, error.msg)
 						&& Objects.equals(oldFileName, error.oldFileName)
-						&& Objects.equals(hh, error.hh);
+						&& Objects.equals(hh, error.hh)
+						&& isGitConflict == error.isGitConflict;
 			}
 
 			@Override
 			public int hashCode() {
-				return Objects.hash(msg, oldFileName, hh);
+				return Objects.hash(msg, oldFileName, hh,
+						Boolean.valueOf(isGitConflict));
 			}
 		}
 
@@ -257,8 +276,14 @@ public List<Error> getErrors() {
 			return errors;
 		}
 
-		private void addError(String msg,String oldFileName, @Nullable HunkHeader hh) {
-			errors.add(new Error(msg, oldFileName, hh));
+		private void addError(String msg, String oldFileName,
+				@Nullable HunkHeader hh) {
+			errors.add(new Error(msg, oldFileName, hh, false));
+		}
+
+		private void addErrorWithGitConflict(String msg, String oldFileName,
+				@Nullable HunkHeader hh) {
+			errors.add(new Error(msg, oldFileName, hh, true));
 		}
 	}
 
@@ -1020,7 +1045,7 @@ && canApplyAt(hunkLines, newLines, 0)) {
 				// only works if the pre-image SHA is contained in the repo.
 				// If that was the case, cherry-picking the original commit
 				// should be preferred to apply a patch.
-				result.addError("cannot apply hunk", fh.getOldPath(), hh); //$NON-NLS-1$
+				result.addErrorWithGitConflict("cannot apply hunk", fh.getOldPath(), hh); //$NON-NLS-1$
 				newLines.add(Math.min(applyAt++, newLines.size()),
 						asBytes("<<<<<<< HEAD")); //$NON-NLS-1$
 				applyAt += hh.getOldImage().lineCount;