From 98111e01c2024ffbc9197664b46119558fedf3b6 Mon Sep 17 00:00:00 2001 From: Constantine Plotnikov Date: Mon, 8 Jun 2009 16:22:20 +0400 Subject: [PATCH] git4idea: Fix to problem with NPE: Directory index is not initialized yet for Project --- plugins/git4idea/src/git4idea/vfs/GitRootTracker.java | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/plugins/git4idea/src/git4idea/vfs/GitRootTracker.java b/plugins/git4idea/src/git4idea/vfs/GitRootTracker.java index 8243b4b05f..ed0377b11b 100644 --- a/plugins/git4idea/src/git4idea/vfs/GitRootTracker.java +++ b/plugins/git4idea/src/git4idea/vfs/GitRootTracker.java @@ -25,6 +25,7 @@ import com.intellij.openapi.command.CommandEvent; import com.intellij.openapi.command.CommandListener; import com.intellij.openapi.command.CommandProcessor; import com.intellij.openapi.project.Project; +import com.intellij.openapi.startup.StartupManager; import com.intellij.openapi.ui.Messages; import com.intellij.openapi.vcs.ProjectLevelVcsManager; import com.intellij.openapi.vcs.VcsDirectoryMapping; @@ -97,6 +98,10 @@ public class GitRootTracker implements VcsListener { * The multicaster for root events */ private GitRootsListener myMulticaster; + /** + * If true, the tracker is enabled, false if project has not yet been intialized. + */ + private AtomicBoolean myIsEnabled = new AtomicBoolean(false); /** * The constructor @@ -137,7 +142,12 @@ public class GitRootTracker implements VcsListener { } }; fileManager.addVirtualFileManagerListener(myVirtualFileManagerListener); - checkRoots(true); + StartupManager.getInstance(myProject).registerPostStartupActivity(new Runnable() { + public void run() { + myIsEnabled.set(true); + checkRoots(true); + } + }); } /** @@ -167,7 +177,7 @@ public class GitRootTracker implements VcsListener { * @param rootsChanged */ private void checkRoots(boolean rootsChanged) { - if (!rootsChanged && !myHasGitRoots.get()) { + if (!myIsEnabled.get() || (!rootsChanged && !myHasGitRoots.get())) { return; } ApplicationManager.getApplication().runReadAction(new Runnable() { -- 2.11.4.GIT