From ea80a589e6f4c49200db599f315c1002cee23b91 Mon Sep 17 00:00:00 2001 From: Aleksey Pivovarov Date: Wed, 19 Feb 2020 13:43:18 +0300 Subject: [PATCH] git: ignore changes that belong to another VCS root GitOrigin-RevId: ea45ef61de4874135270b515b4a460fbd9cfbafe --- .../src/git4idea/repo/GitUntrackedFilesHolder.java | 12 +++++++++++- .../src/git4idea/status/GitChangesCollector.java | 14 +++++++++++++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/plugins/git4idea/src/git4idea/repo/GitUntrackedFilesHolder.java b/plugins/git4idea/src/git4idea/repo/GitUntrackedFilesHolder.java index 81b853aa49ee..df2e8f8bfa8b 100644 --- a/plugins/git4idea/src/git4idea/repo/GitUntrackedFilesHolder.java +++ b/plugins/git4idea/src/git4idea/repo/GitUntrackedFilesHolder.java @@ -198,10 +198,20 @@ public class GitUntrackedFilesHolder implements Disposable, AsyncVfsEventsListen Set untrackedFiles = myGit.untrackedFilePaths(myProject, myRoot, suspiciousFiles); + untrackedFiles.removeIf(it -> { + VirtualFile root = myVcsManager.getVcsRootFor(it); + if (!myRoot.equals(root)) { + LOG.warn(String.format("Ignoring untracked file under another root: %s; root: %s; mapped root: %s", it, myRoot, root)); + return true; + } + return false; + }); + + synchronized (LOCK) { if (suspiciousFiles != null) { // files that were suspicious (and thus passed to 'git ls-files'), but are not untracked, are definitely tracked. - myDefinitelyUntrackedFiles.removeIf((definitelyUntrackedFile)-> isUnder(myRootPath, suspiciousFiles, definitelyUntrackedFile)); + myDefinitelyUntrackedFiles.removeIf((definitelyUntrackedFile) -> isUnder(myRootPath, suspiciousFiles, definitelyUntrackedFile)); myDefinitelyUntrackedFiles.addAll(untrackedFiles); } else { diff --git a/plugins/git4idea/src/git4idea/status/GitChangesCollector.java b/plugins/git4idea/src/git4idea/status/GitChangesCollector.java index 9bbccd759b25..c036d3cf6125 100644 --- a/plugins/git4idea/src/git4idea/status/GitChangesCollector.java +++ b/plugins/git4idea/src/git4idea/status/GitChangesCollector.java @@ -15,6 +15,7 @@ */ package git4idea.status; +import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.util.text.StringUtil; @@ -53,6 +54,8 @@ import java.util.*; * @author Kirill Likhodedov */ class GitChangesCollector { + private static final Logger LOG = Logger.getInstance(GitChangesCollector.class); + @NotNull private final Project myProject; @NotNull private final Git myGit; @NotNull private final GitRepository myRepository; @@ -461,6 +464,15 @@ class GitChangesCollector { } private void reportChange(FileStatus status, ContentRevision before, ContentRevision after) { - myChanges.add(new Change(before, after, status)); + Change change = new Change(before, after, status); + + FilePath filePath = ChangesUtil.getFilePath(change); + VirtualFile root = ProjectLevelVcsManager.getInstance(myProject).getVcsRootFor(filePath); + if (!myVcsRoot.equals(root)) { + LOG.warn(String.format("Ignoring change under another root: %s; root: %s; mapped root: %s", change, myVcsRoot, root)); + return; + } + + myChanges.add(change); } }