From 40ef04e8cc5209cf1b8a72bbcdc2f3ac540bedd6 Mon Sep 17 00:00:00 2001 From: Nadya Zabrodina Date: Tue, 27 Oct 2015 16:07:07 +0300 Subject: [PATCH] [patch]: IDEA-146642 unexpected mapping on applying a VCS patch * tests added --- .../intellij/openapi/vcs/changes/patch/MatchPatchPaths.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/patch/MatchPatchPaths.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/patch/MatchPatchPaths.java index 03da20ba2743..a319edc40f8b 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/patch/MatchPatchPaths.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/patch/MatchPatchPaths.java @@ -89,7 +89,7 @@ public class MatchPatchPaths { for (VirtualFile file : files) { Pair pair = compareNamesImpl(strings, file, i); if (pair != null && pair.getSecond() < i) { - if (best == null || pair.getSecond() < best.getSecond()) { + if (best == null || pair.getSecond() < best.getSecond() || isGoodAndProjectBased(best, pair)) { best = pair; } } @@ -110,6 +110,10 @@ public class MatchPatchPaths { } } + private boolean isGoodAndProjectBased(@NotNull Pair best, @NotNull Pair pair) { + return pair.getSecond().equals(best.getSecond()) && myBaseDir.equals(pair.getFirst()); + } + private static void selectByContextOrByStrip(@NotNull List candidates, @NotNull MultiMap result) { for (final PatchAndVariants candidate : candidates) {