[git] IDEA-91996 Guess repository if there are no virtual files in the scope

This commit is contained in:
Kirill Likhodedov
2015-05-08 18:49:21 +03:00
parent cc077fce25
commit df63f2a5ac
@@ -15,6 +15,7 @@
*/
package git4idea.actions;
import com.intellij.dvcs.repo.Repository;
import com.intellij.openapi.actionSystem.ActionPlaces;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.CommonDataKeys;
@@ -114,19 +115,18 @@ public abstract class GitRepositoryAction extends DumbAwareAction {
if (files != null) {
for (VirtualFile file : files) {
GitRepositoryManager manager = GitUtil.getRepositoryManager(project);
if (manager == null) {
return false;
}
final GitRepository repositoryForFile = manager.getRepositoryForFile(file);
if (repositoryForFile != null && repositoryForFile.getState() == GitRepository.State.REBASING) {
return true;
}
if (isRebasing(manager.getRepositoryForFile(file))) return true;
}
}
if (isRebasing(GitBranchUtil.getCurrentRepository(project))) return true;
}
return false;
}
private static boolean isRebasing(@Nullable GitRepository repository) {
return repository != null && repository.getState() == Repository.State.REBASING;
}
/**
* Get git roots for the project. The method shows dialogs in the case when roots cannot be retrieved, so it should be called
* from the event dispatch thread.