summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit
diff options
context:
space:
mode:
authorTerry Parker <tparker@google.com>2020-09-03 18:35:24 -0400
committerGerrit Code Review @ Eclipse.org <gerrit@eclipse.org>2020-09-03 18:35:24 -0400
commit957419610ad1af3791ff0c279bbc7cbadabd810d (patch)
tree593b818bcc12ac8b2853b50d7b18be546920b66b /org.eclipse.jgit
parentdf6a1c55fa12a296476848e2b2fa1842abafa46d (diff)
parent214c4afc2c9a7306ac989df218b7cab30ee5e026 (diff)
downloadjgit-957419610ad1af3791ff0c279bbc7cbadabd810d.tar.gz
jgit-957419610ad1af3791ff0c279bbc7cbadabd810d.zip
Merge changes from topic "fix_ui"
* changes: ResolveMerger: do not content-merge gitlinks on del/mod conflicts ResolveMerger: Adding test cases for GITLINK deletion ResolveMerger: choose OURS on gitlink when ignoreConflicts ResolveMerger: improving content merge readability ResolveMerger: extracting createGitLinksMergeResult method ResolveMerger: Adding test cases for GITLINK merge
Diffstat (limited to 'org.eclipse.jgit')
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/merge/ResolveMerger.java124
1 files changed, 75 insertions, 49 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/merge/ResolveMerger.java b/org.eclipse.jgit/src/org/eclipse/jgit/merge/ResolveMerger.java
index 506d333120..6c217fdf25 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/merge/ResolveMerger.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/merge/ResolveMerger.java
@@ -588,7 +588,8 @@ public class ResolveMerger extends ThreeWayMerger {
final int modeO = tw.getRawMode(T_OURS);
final int modeT = tw.getRawMode(T_THEIRS);
final int modeB = tw.getRawMode(T_BASE);
-
+ boolean gitLinkMerging = isGitLink(modeO) || isGitLink(modeT)
+ || isGitLink(modeB);
if (modeO == 0 && modeT == 0 && modeB == 0)
// File is either untracked or new, staged but uncommitted
return true;
@@ -737,31 +738,28 @@ public class ResolveMerger extends ThreeWayMerger {
return false;
}
- boolean gitlinkConflict = isGitLink(modeO) || isGitLink(modeT);
- // Don't attempt to resolve submodule link conflicts
- if (gitlinkConflict || !attributes.canBeContentMerged()) {
+ if (gitLinkMerging && ignoreConflicts) {
+ // Always select 'ours' in case of GITLINK merge failures so
+ // a caller can use virtual commit.
+ add(tw.getRawPath(), ours, DirCacheEntry.STAGE_0, EPOCH, 0);
+ return true;
+ } else if (gitLinkMerging) {
+ add(tw.getRawPath(), base, DirCacheEntry.STAGE_1, EPOCH, 0);
+ add(tw.getRawPath(), ours, DirCacheEntry.STAGE_2, EPOCH, 0);
+ add(tw.getRawPath(), theirs, DirCacheEntry.STAGE_3, EPOCH, 0);
+ MergeResult<SubmoduleConflict> result = createGitLinksMergeResult(
+ base, ours, theirs);
+ result.setContainsConflicts(true);
+ mergeResults.put(tw.getPathString(), result);
+ unmergedPaths.add(tw.getPathString());
+ return true;
+ } else if (!attributes.canBeContentMerged()) {
add(tw.getRawPath(), base, DirCacheEntry.STAGE_1, EPOCH, 0);
add(tw.getRawPath(), ours, DirCacheEntry.STAGE_2, EPOCH, 0);
add(tw.getRawPath(), theirs, DirCacheEntry.STAGE_3, EPOCH, 0);
- if (gitlinkConflict) {
- MergeResult<SubmoduleConflict> result = new MergeResult<>(
- Arrays.asList(
- new SubmoduleConflict(base == null ? null
- : base.getEntryObjectId()),
- new SubmoduleConflict(ours == null ? null
- : ours.getEntryObjectId()),
- new SubmoduleConflict(theirs == null ? null
- : theirs.getEntryObjectId())));
- result.setContainsConflicts(true);
- mergeResults.put(tw.getPathString(), result);
- if (!ignoreConflicts) {
- unmergedPaths.add(tw.getPathString());
- }
- } else {
- // attribute merge issues are conflicts but not failures
- unmergedPaths.add(tw.getPathString());
- }
+ // attribute merge issues are conflicts but not failures
+ unmergedPaths.add(tw.getPathString());
return true;
}
@@ -786,45 +784,73 @@ public class ResolveMerger extends ThreeWayMerger {
// OURS or THEIRS has been deleted
if (((modeO != 0 && !tw.idEqual(T_BASE, T_OURS)) || (modeT != 0 && !tw
.idEqual(T_BASE, T_THEIRS)))) {
- MergeResult<RawText> result = contentMerge(base, ours, theirs,
- attributes);
-
- if (ignoreConflicts) {
- // In case a conflict is detected the working tree file is
- // again filled with new content (containing conflict
- // markers). But also stage 0 of the index is filled with
- // that content.
- result.setContainsConflicts(false);
- updateIndex(base, ours, theirs, result, attributes);
- } else {
+ if (gitLinkMerging && ignoreConflicts) {
+ add(tw.getRawPath(), ours, DirCacheEntry.STAGE_0, EPOCH, 0);
+ } else if (gitLinkMerging) {
add(tw.getRawPath(), base, DirCacheEntry.STAGE_1, EPOCH, 0);
add(tw.getRawPath(), ours, DirCacheEntry.STAGE_2, EPOCH, 0);
- DirCacheEntry e = add(tw.getRawPath(), theirs,
- DirCacheEntry.STAGE_3, EPOCH, 0);
-
- // OURS was deleted checkout THEIRS
- if (modeO == 0) {
- // Check worktree before checking out THEIRS
- if (isWorktreeDirty(work, ourDce)) {
- return false;
- }
- if (nonTree(modeT)) {
- if (e != null) {
- addToCheckout(tw.getPathString(), e, attributes);
+ add(tw.getRawPath(), theirs, DirCacheEntry.STAGE_3, EPOCH, 0);
+ MergeResult<SubmoduleConflict> result = createGitLinksMergeResult(
+ base, ours, theirs);
+ result.setContainsConflicts(true);
+ mergeResults.put(tw.getPathString(), result);
+ unmergedPaths.add(tw.getPathString());
+ } else {
+ MergeResult<RawText> result = contentMerge(base, ours,
+ theirs, attributes);
+
+ if (ignoreConflicts) {
+ // In case a conflict is detected the working tree file
+ // is again filled with new content (containing conflict
+ // markers). But also stage 0 of the index is filled
+ // with that content.
+ result.setContainsConflicts(false);
+ updateIndex(base, ours, theirs, result, attributes);
+ } else {
+ add(tw.getRawPath(), base, DirCacheEntry.STAGE_1, EPOCH,
+ 0);
+ add(tw.getRawPath(), ours, DirCacheEntry.STAGE_2, EPOCH,
+ 0);
+ DirCacheEntry e = add(tw.getRawPath(), theirs,
+ DirCacheEntry.STAGE_3, EPOCH, 0);
+
+ // OURS was deleted checkout THEIRS
+ if (modeO == 0) {
+ // Check worktree before checking out THEIRS
+ if (isWorktreeDirty(work, ourDce)) {
+ return false;
+ }
+ if (nonTree(modeT)) {
+ if (e != null) {
+ addToCheckout(tw.getPathString(), e,
+ attributes);
+ }
}
}
- }
- unmergedPaths.add(tw.getPathString());
+ unmergedPaths.add(tw.getPathString());
- // generate a MergeResult for the deleted file
- mergeResults.put(tw.getPathString(), result);
+ // generate a MergeResult for the deleted file
+ mergeResults.put(tw.getPathString(), result);
+ }
}
}
}
return true;
}
+ private static MergeResult<SubmoduleConflict> createGitLinksMergeResult(
+ CanonicalTreeParser base, CanonicalTreeParser ours,
+ CanonicalTreeParser theirs) {
+ return new MergeResult<>(Arrays.asList(
+ new SubmoduleConflict(
+ base == null ? null : base.getEntryObjectId()),
+ new SubmoduleConflict(
+ ours == null ? null : ours.getEntryObjectId()),
+ new SubmoduleConflict(
+ theirs == null ? null : theirs.getEntryObjectId())));
+ }
+
/**
* Does the content merge. The three texts base, ours and theirs are
* specified with {@link CanonicalTreeParser}. If any of the parsers is