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) {