IDEA-66127 Git SSH executable as a system wide setting: correctly migrate from worksp...
authorKirill Likhodedov <Kirill.Likhodedov@jetbrains.com>
Thu, 2 Aug 2012 11:52:02 +0000 (15:52 +0400)
committerKirill Likhodedov <Kirill.Likhodedov@jetbrains.com>
Thu, 2 Aug 2012 12:21:17 +0000 (16:21 +0400)
plugins/git4idea/src/git4idea/commands/GitHandler.java
plugins/git4idea/src/git4idea/config/GitVcsApplicationSettings.java
plugins/git4idea/src/git4idea/config/GitVcsPanel.java
plugins/git4idea/src/git4idea/config/GitVcsSettings.java

index 5c51ad42d56003553b8d69441b117a58170fcb9e..4835b3d27328a2b5e771853fffaffb108f44b067 100644 (file)
@@ -403,7 +403,7 @@ public abstract class GitHandler {
       }
 
       // setup environment
-      if (!myNoSSHFlag && myAppSettings.isIdeaSsh()) {
+      if (!myNoSSHFlag && myProjectSettings.isIdeaSsh()) {
         GitSSHService ssh = GitSSHIdeaService.getInstance();
         myEnv.put(GitSSHHandler.GIT_SSH_ENV, ssh.getScriptPath().getPath());
         myHandlerNo = ssh.registerHandler(new GitSSHGUIHandler(myProject));
index b11136dc24518213c4d1f06cec54a3fc3429eecf..6542c65311ef2bc4e0b96b63d1cd3eb7e15a6697 100644 (file)
@@ -19,6 +19,7 @@ import com.intellij.openapi.components.*;
 import com.intellij.openapi.util.SystemInfo;
 import org.jetbrains.annotations.NonNls;
 import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
 
 import java.io.File;
 
@@ -47,7 +48,7 @@ public class GitVcsApplicationSettings implements PersistentStateComponent<GitVc
 
   public static class State {
     public String myPathToGit = null;
-    public SshExecutable SSH_EXECUTABLE = SshExecutable.IDEA_SSH;
+    public SshExecutable SSH_EXECUTABLE = null;
   }
 
   public static GitVcsApplicationSettings getInstance() {
@@ -102,12 +103,13 @@ public class GitVcsApplicationSettings implements PersistentStateComponent<GitVc
     myState.myPathToGit = pathToGit;
   }
 
-  public boolean isIdeaSsh() {
-    return myState.SSH_EXECUTABLE == SshExecutable.IDEA_SSH;
+  public void setIdeaSsh(@NotNull SshExecutable executable) {
+    myState.SSH_EXECUTABLE = executable;
   }
 
-  public void setIdeaSsh(boolean value) {
-    myState.SSH_EXECUTABLE = value ? SshExecutable.IDEA_SSH : SshExecutable.NATIVE_SSH;
+  @Nullable
+  SshExecutable getIdeaSsh() {
+    return myState.SSH_EXECUTABLE;
   }
 
 }
index 51fa124cfc9b772e6b00202209cc53b766d00fd0..2ae1f0966be630a59ba3b03bd5dd9f8591813f09 100644 (file)
@@ -125,7 +125,7 @@ public class GitVcsPanel {
    */
   public void load(@NotNull GitVcsSettings settings) {
     myGitField.setText(settings.getAppSettings().getPathToGit());
-    mySSHExecutableComboBox.setSelectedItem(settings.getAppSettings().isIdeaSsh() ? IDEA_SSH : NATIVE_SSH);
+    mySSHExecutableComboBox.setSelectedItem(settings.isIdeaSsh() ? IDEA_SSH : NATIVE_SSH);
     myConvertTextFilesComboBox.setSelectedItem(crlfPolicyItem(settings));
     myAutoUpdateIfPushRejected.setSelected(settings.autoUpdateIfPushRejected());
     mySyncBranchControl.setSelected(settings.getSyncSetting() == GitBranchSyncSetting.SYNC);
@@ -164,7 +164,7 @@ public class GitVcsPanel {
    */
   public boolean isModified(@NotNull GitVcsSettings settings) {
     return !settings.getAppSettings().getPathToGit().equals(getCurrentExecutablePath()) ||
-           (settings.getAppSettings().isIdeaSsh() != IDEA_SSH.equals(mySSHExecutableComboBox.getSelectedItem())) ||
+           (settings.isIdeaSsh() != IDEA_SSH.equals(mySSHExecutableComboBox.getSelectedItem())) ||
            !crlfPolicyItem(settings).equals(myConvertTextFilesComboBox.getSelectedItem()) ||
            !settings.autoUpdateIfPushRejected() == myAutoUpdateIfPushRejected.isSelected() ||
            ((settings.getSyncSetting() == GitBranchSyncSetting.SYNC) != mySyncBranchControl.isSelected() ||
@@ -179,7 +179,9 @@ public class GitVcsPanel {
   public void save(@NotNull GitVcsSettings settings) {
     settings.getAppSettings().setPathToGit(getCurrentExecutablePath());
     myVcs.checkVersion();
-    settings.getAppSettings().setIdeaSsh(IDEA_SSH.equals(mySSHExecutableComboBox.getSelectedItem()));
+    settings.getAppSettings().setIdeaSsh(IDEA_SSH.equals(mySSHExecutableComboBox.getSelectedItem()) ?
+                                         GitVcsApplicationSettings.SshExecutable.IDEA_SSH :
+                                         GitVcsApplicationSettings.SshExecutable.NATIVE_SSH);
     settings.setAutoUpdateIfPushRejected(myAutoUpdateIfPushRejected.isSelected());
 
     Object policyItem = myConvertTextFilesComboBox.getSelectedItem();
index c49a73d16ddf656610cb601be488eb4163a894af..3ea9e9d50f3e88cb709caa3264401b4f933d1736 100644 (file)
@@ -59,6 +59,7 @@ public class GitVcsSettings implements PersistentStateComponent<GitVcsSettings.S
   public static class State {
     // The previously entered authors of the commit (up to {@value #PREVIOUS_COMMIT_AUTHORS_LIMIT})
     public List<String> PREVIOUS_COMMIT_AUTHORS = new ArrayList<String>();
+    public GitVcsApplicationSettings.SshExecutable SSH_EXECUTABLE = GitVcsApplicationSettings.SshExecutable.IDEA_SSH;
     // The policy that specifies how files are saved before update or rebase
     public UpdateChangesPolicy UPDATE_CHANGES_POLICY = UpdateChangesPolicy.STASH;
     public UpdateMethod UPDATE_TYPE = UpdateMethod.BRANCH_DEFAULT;
@@ -185,4 +186,16 @@ public class GitVcsSettings implements PersistentStateComponent<GitVcsSettings.S
     return myState.AUTO_COMMIT_ON_CHERRY_PICK;
   }
 
+  /**
+   * Provides migration from project settings.
+   * This method is to be removed in IDEA 13: it should be moved to {@link GitVcsApplicationSettings}
+   */
+  @Deprecated
+  public boolean isIdeaSsh() {
+    if (getAppSettings().getIdeaSsh() == null) { // app setting has not been initialized yet => migrate the project setting there
+      getAppSettings().setIdeaSsh(myState.SSH_EXECUTABLE);
+    }
+    return getAppSettings().getIdeaSsh() == GitVcsApplicationSettings.SshExecutable.IDEA_SSH;
+  }
+
 }