summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit
diff options
context:
space:
mode:
authorPatrick Hiesel <hiesel@google.com>2024-05-27 16:11:40 +0200
committerMatthias Sohn <matthias.sohn@sap.com>2024-05-27 18:57:19 +0200
commitc0c59ccf2d320c1d50f3ad949e5369ae167b8fb5 (patch)
tree22f2528f9bb7cfcb7fa4bc8fcb3eefa40956867d /org.eclipse.jgit
parentf5f33be8ca9b49c506d6f0ea296b65c5d649aaa4 (diff)
downloadjgit-c0c59ccf2d320c1d50f3ad949e5369ae167b8fb5.tar.gz
jgit-c0c59ccf2d320c1d50f3ad949e5369ae167b8fb5.zip
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
Diffstat (limited to 'org.eclipse.jgit')
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/patch/PatchApplier.java37
1 files changed, 31 insertions, 6 deletions
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 84c2ec43dc..1a98d79f99 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 class PatchApplier {
@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 class PatchApplier {
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 class PatchApplier {
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 @@ public class PatchApplier {
// 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;