Skip to content

Commit

Permalink
Fixed bug where GitRepositoryManager is null when trying to update th…
Browse files Browse the repository at this point in the history
…e tool window after initializing git in a project
  • Loading branch information
kpatenio committed Jul 30, 2020
1 parent cb16720 commit c24236b
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.DataContext;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.popup.JBPopup;
import com.intellij.openapi.ui.popup.JBPopupFactory;
import com.intellij.ui.components.JBLabel;
Expand All @@ -19,15 +18,10 @@
public class ShowExplanationsToolWindowAction extends AnAction {
@Override
public void update(AnActionEvent e) {
Project project = e.getProject();
if (e.getProject() != null) {
GitRepository repo = Utils.getCurrentRepository(project);
boolean isInGit = Utils.isInGitRepository(project);
boolean isInConflict = Utils.isInConflictState(repo);
boolean shouldActionBeVisible = isInGit && isInConflict;
e.getPresentation().setVisible(shouldActionBeVisible);
GitRepository repo = Utils.getCurrentRepository(e.getProject());
e.getPresentation().setVisible(repo != null && Utils.isInConflictState(repo));

// System.out.println(e.getDataContext());
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ public static void updateToolWindowAfterAction(GitRepository repo) {

public static void updateToolWindowAfterNonConflictState(GitRepository repo) {
assert !Utils.isInConflictState(repo);
if (manager.getToolWindow(
// If manager is null, this means that the update function for non
// conflict state was called outside of a context menu action.
// Ex. initializing git for a project.
if (manager != null && manager.getToolWindow(
ExplainMergeConflictBundle.message("toolwindow.id")) != null) {
unregisterToolWindow();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.openapi.wm.ToolWindow;
import com.intellij.openapi.wm.ToolWindowAnchor;
import com.intellij.openapi.wm.ToolWindowManager;
import com.sun.istack.NotNull;
import git4idea.repo.GitConflictsHolder;
import git4idea.repo.GitRepository;
import org.ualberta.smr.explainmergeconflict.utils.Utils;

Expand Down Expand Up @@ -41,8 +37,6 @@ public ExplanationsToolWindow(GitRepository repo,
}

private void initializeToolWindow() {
// FIXME - do not initialize plugin if no repo or no file upon
// initialization
updateUIIfMergeConflictState();
// updateBackgroundColors();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,9 @@ public static boolean isInGitRepository(Project project) {
* @return current repository
*/
public static GitRepository getCurrentRepository(Project project) {
// FIXME run this assertion in another function
assert !GitRepositoryManager.getInstance(project)
.getRepositories()
.isEmpty();
if (!isInGitRepository(project)) {
return null;
}
return GitRepositoryManager.getInstance(project)
.getRepositories()
.get(0);
Expand Down

0 comments on commit c24236b

Please sign in to comment.