/**
  * The constructor
  *
  * @param project the context project
  */
 public GitVcsPanel(@NotNull Project project) {
   myVcs = GitVcs.getInstance(project);
   myAppSettings = GitVcsApplicationSettings.getInstance();
   myProjectSettings = GitVcsSettings.getInstance(project);
   myProject = project;
   mySSHExecutableComboBox.addItem(IDEA_SSH);
   mySSHExecutableComboBox.addItem(NATIVE_SSH);
   mySSHExecutableComboBox.setSelectedItem(
       GitVcsSettings.isDefaultIdeaSsh() ? IDEA_SSH : NATIVE_SSH);
   mySSHExecutableComboBox.setToolTipText(
       GitBundle.message(
           "git.vcs.config.ssh.mode.tooltip",
           ApplicationNamesInfo.getInstance().getFullProductName()));
   myTestButton.addActionListener(
       new ActionListener() {
         public void actionPerformed(ActionEvent e) {
           testConnection();
         }
       });
   myConvertTextFilesComboBox.addItem(CRLF_DO_NOT_CONVERT);
   myConvertTextFilesComboBox.addItem(CRLF_CONVERT_TO_PROJECT);
   myConvertTextFilesComboBox.addItem(CRLF_ASK);
   myConvertTextFilesComboBox.setSelectedItem(CRLF_ASK);
   myGitField.addBrowseFolderListener(
       GitBundle.getString("find.git.title"),
       GitBundle.getString("find.git.description"),
       project,
       new FileChooserDescriptor(true, false, false, false, false, false));
 }
  private void checkExecutableAndVersion() {
    boolean executableIsAlreadyCheckedAndFine = false;
    String pathToGit = myAppSettings.getPathToGit();
    if (!pathToGit.contains(
        File.separator)) { // no path, just sole executable, with a hope that it is in path
      // subject to redetect the path if executable validator fails
      if (!myExecutableValidator.isExecutableValid()) {
        myAppSettings.setPathToGit(new GitExecutableDetector().detect());
      } else {
        executableIsAlreadyCheckedAndFine = true; // not to check it twice
      }
    }

    if (executableIsAlreadyCheckedAndFine
        || myExecutableValidator.checkExecutableAndNotifyIfNeeded()) {
      checkVersion();
    }
  }
  public static boolean testGitExecutable(final Project project) {
    final GitVcsApplicationSettings settings = GitVcsApplicationSettings.getInstance();
    final String executable = settings.getPathToGit();
    final GitVersion version;
    try {
      version = GitVersion.identifyVersion(executable);
    } catch (Exception e) {
      Messages.showErrorDialog(
          project, e.getMessage(), GitBundle.getString("find.git.error.title"));
      return false;
    }

    if (!version.isSupported()) {
      Messages.showWarningDialog(
          project,
          GitBundle.message("find.git.unsupported.message", version.toString(), GitVersion.MIN),
          GitBundle.getString("find.git.success.title"));
      return false;
    }
    return true;
  }
 /**
  * Checks Git version and updates the myVersion variable. In the case of exception or unsupported
  * version reports the problem. Note that unsupported version is also applied - some functionality
  * might not work (we warn about that), but no need to disable at all.
  */
 public void checkVersion() {
   final String executable = myAppSettings.getPathToGit();
   try {
     myVersion = GitVersion.identifyVersion(executable);
     if (!myVersion.isSupported()) {
       log.info("Unsupported Git version: " + myVersion);
       final String SETTINGS_LINK = "settings";
       final String UPDATE_LINK = "update";
       String message =
           String.format(
               "The <a href='"
                   + SETTINGS_LINK
                   + "'>configured</a> version of Git is not supported: %s.<br/> "
                   + "The minimal supported version is %s. Please <a href='"
                   + UPDATE_LINK
                   + "'>update</a>.",
               myVersion,
               GitVersion.MIN);
       VcsNotifier.getInstance(myProject)
           .notifyError(
               "Unsupported Git version",
               message,
               new NotificationListener.Adapter() {
                 @Override
                 protected void hyperlinkActivated(
                     @NotNull Notification notification, @NotNull HyperlinkEvent e) {
                   if (SETTINGS_LINK.equals(e.getDescription())) {
                     ShowSettingsUtil.getInstance()
                         .showSettingsDialog(myProject, getConfigurable().getDisplayName());
                   } else if (UPDATE_LINK.equals(e.getDescription())) {
                     BrowserUtil.browse("http://git-scm.com");
                   }
                 }
               });
     }
   } catch (Exception e) {
     if (getExecutableValidator()
         .checkExecutableAndNotifyIfNeeded()) { // check executable before notifying error
       final String reason = (e.getCause() != null ? e.getCause() : e).getMessage();
       String message = GitBundle.message("vcs.unable.to.run.git", executable, reason);
       if (!myProject.isDefault()) {
         showMessage(message, ConsoleViewContentType.SYSTEM_OUTPUT.getAttributes());
       }
       VcsBalloonProblemNotifier.showOverVersionControlView(myProject, message, MessageType.ERROR);
     }
   }
 }
  /** Test availability of the connection */
  private void testConnection() {
    final String executable = myGitField.getText();
    if (myAppSettings != null) {
      myAppSettings.setPathToGit(executable);
    }
    final GitVersion version;
    try {
      version = GitVersion.identifyVersion(executable);
    } catch (Exception e) {
      Messages.showErrorDialog(
          myProject, e.getMessage(), GitBundle.getString("find.git.error.title"));
      return;
    }

    if (version.isSupported()) {
      Messages.showInfoMessage(
          myProject, version.toString(), GitBundle.getString("find.git.success.title"));
    } else {
      Messages.showWarningDialog(
          myProject,
          GitBundle.message("find.git.unsupported.message", version.toString(), GitVersion.MIN),
          GitBundle.getString("find.git.success.title"));
    }
  }