private UnionScope(@NotNull GlobalSearchScope[] scopes) {
   super(
       ContainerUtil.getFirstItem(
           ContainerUtil.mapNotNull(
               scopes,
               new Function<GlobalSearchScope, Project>() {
                 @Override
                 public Project fun(GlobalSearchScope scope) {
                   return scope.getProject();
                 }
               }),
           null));
   if (scopes.length <= 1)
     throw new IllegalArgumentException("Too few scopes: " + Arrays.asList(scopes));
   myScopes = scopes;
   final int[] nested = {0};
   ContainerUtil.process(
       scopes,
       new Processor<GlobalSearchScope>() {
         @Override
         public boolean process(GlobalSearchScope scope) {
           nested[0] =
               Math.max(
                   nested[0],
                   scope instanceof UnionScope ? ((UnionScope) scope).myNestingLevel : 0);
           return true;
         }
       });
   myNestingLevel = 1 + nested[0];
   if (myNestingLevel > 1000) {
     throw new IllegalStateException(
         "Too many scopes combined: " + myNestingLevel + StringUtil.last(toString(), 500, true));
   }
 }
    private ReturnResult warnAboutDetachedHeadIfNeeded() {
      // Warning: commit on a detached HEAD
      DetachedRoot detachedRoot = getDetachedRoot();
      if (detachedRoot == null) {
        return ReturnResult.COMMIT;
      }

      final String title;
      final String message;
      final CharSequence rootPath =
          StringUtil.last(detachedRoot.myRoot.getPresentableUrl(), 50, true);
      final String messageCommonStart = "The Git repository <code>" + rootPath + "</code>";
      if (detachedRoot.myRebase) {
        title = "Unfinished rebase process";
        message =
            messageCommonStart
                + " <br/> has an <b>unfinished rebase</b> process. <br/>"
                + "You probably want to <b>continue rebase</b> instead of committing. <br/>"
                + "Committing during rebase may lead to the commit loss. <br/>"
                + readMore(
                    "http://www.kernel.org/pub/software/scm/git/docs/git-rebase.html",
                    "Read more about Git rebase");
      } else {
        title = "Commit in detached HEAD may be dangerous";
        message =
            messageCommonStart
                + " is in the <b>detached HEAD</b> state. <br/>"
                + "You can look around, make experimental changes and commit them, but be sure to checkout a branch not to lose your work. <br/>"
                + "Otherwise you risk losing your changes. <br/>"
                + readMore(
                    "http://sitaramc.github.com/concepts/detached-head.html",
                    "Read more about detached HEAD");
      }

      final int choice =
          Messages.showOkCancelDialog(
              myPanel.getComponent(),
              XmlStringUtil.wrapInHtml(message),
              title,
              "Cancel",
              "Commit",
              Messages.getWarningIcon());
      if (choice != Messages.OK) {
        return ReturnResult.COMMIT;
      } else {
        return ReturnResult.CLOSE_WINDOW;
      }
    }