IDEA-66127 Git SSH executable as a system wide setting
authorKirill Likhodedov <Kirill.Likhodedov@jetbrains.com>
Wed, 1 Aug 2012 14:30:38 +0000 (18:30 +0400)
committerKirill Likhodedov <Kirill.Likhodedov@jetbrains.com>
Wed, 1 Aug 2012 14:30:38 +0000 (18:30 +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 4835b3d27328a2b5e771853fffaffb108f44b067..5c51ad42d56003553b8d69441b117a58170fcb9e 100644 (file)
@@ -403,7 +403,7 @@ public abstract class GitHandler {
       }
 
       // setup environment
-      if (!myNoSSHFlag && myProjectSettings.isIdeaSsh()) {
+      if (!myNoSSHFlag && myAppSettings.isIdeaSsh()) {
         GitSSHService ssh = GitSSHIdeaService.getInstance();
         myEnv.put(GitSSHHandler.GIT_SSH_ENV, ssh.getScriptPath().getPath());
         myHandlerNo = ssh.registerHandler(new GitSSHGUIHandler(myProject));
index bf1fd7f991ef6e2263b51111d7f8028456332b39..b11136dc24518213c4d1f06cec54a3fc3429eecf 100644 (file)
@@ -37,8 +37,17 @@ public class GitVcsApplicationSettings implements PersistentStateComponent<GitVc
   
   private State myState = new State();
 
+  /**
+   * Kinds of SSH executable to be used with the git
+   */
+  public enum SshExecutable {
+    IDEA_SSH,
+    NATIVE_SSH,
+  }
+
   public static class State {
     public String myPathToGit = null;
+    public SshExecutable SSH_EXECUTABLE = SshExecutable.IDEA_SSH;
   }
 
   public static GitVcsApplicationSettings getInstance() {
@@ -93,4 +102,12 @@ public class GitVcsApplicationSettings implements PersistentStateComponent<GitVc
     myState.myPathToGit = pathToGit;
   }
 
+  public boolean isIdeaSsh() {
+    return myState.SSH_EXECUTABLE == SshExecutable.IDEA_SSH;
+  }
+
+  public void setIdeaSsh(boolean value) {
+    myState.SSH_EXECUTABLE = value ? SshExecutable.IDEA_SSH : SshExecutable.NATIVE_SSH;
+  }
+
 }
index e3d19b1f513178e9778f4dd0517bd5b98802e739..51fa124cfc9b772e6b00202209cc53b766d00fd0 100644 (file)
@@ -125,7 +125,7 @@ public class GitVcsPanel {
    */
   public void load(@NotNull GitVcsSettings settings) {
     myGitField.setText(settings.getAppSettings().getPathToGit());
-    mySSHExecutableComboBox.setSelectedItem(settings.isIdeaSsh() ? IDEA_SSH : NATIVE_SSH);
+    mySSHExecutableComboBox.setSelectedItem(settings.getAppSettings().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.isIdeaSsh() != IDEA_SSH.equals(mySSHExecutableComboBox.getSelectedItem())) ||
+           (settings.getAppSettings().isIdeaSsh() != IDEA_SSH.equals(mySSHExecutableComboBox.getSelectedItem())) ||
            !crlfPolicyItem(settings).equals(myConvertTextFilesComboBox.getSelectedItem()) ||
            !settings.autoUpdateIfPushRejected() == myAutoUpdateIfPushRejected.isSelected() ||
            ((settings.getSyncSetting() == GitBranchSyncSetting.SYNC) != mySyncBranchControl.isSelected() ||
@@ -179,7 +179,7 @@ public class GitVcsPanel {
   public void save(@NotNull GitVcsSettings settings) {
     settings.getAppSettings().setPathToGit(getCurrentExecutablePath());
     myVcs.checkVersion();
-    settings.setIdeaSsh(IDEA_SSH.equals(mySSHExecutableComboBox.getSelectedItem()));
+    settings.getAppSettings().setIdeaSsh(IDEA_SSH.equals(mySSHExecutableComboBox.getSelectedItem()));
     settings.setAutoUpdateIfPushRejected(myAutoUpdateIfPushRejected.isSelected());
 
     Object policyItem = myConvertTextFilesComboBox.getSelectedItem();
index c899e7b5bdeca4852604ef09f718bc16541fb5da..c49a73d16ddf656610cb601be488eb4163a894af 100644 (file)
-/*\r
- * Copyright 2000-2012 JetBrains s.r.o.\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-package git4idea.config;\r
-\r
-import com.intellij.lifecycle.PeriodicalTasksCloser;\r
-import com.intellij.openapi.components.PersistentStateComponent;\r
-import com.intellij.openapi.components.State;\r
-import com.intellij.openapi.components.Storage;\r
-import com.intellij.openapi.components.StoragePathMacros;\r
-import com.intellij.openapi.project.Project;\r
-import com.intellij.util.ArrayUtil;\r
-import git4idea.ui.branch.GitBranchSyncSetting;\r
-import org.jetbrains.annotations.NotNull;\r
-import org.jetbrains.annotations.Nullable;\r
-\r
-import java.util.ArrayList;\r
-import java.util.HashMap;\r
-import java.util.List;\r
-import java.util.Map;\r
-\r
-/**\r
- * Git VCS settings\r
- */\r
-@State(name = "Git.Settings", storages = {@Storage(file = StoragePathMacros.WORKSPACE_FILE)})\r
-public class GitVcsSettings implements PersistentStateComponent<GitVcsSettings.State> {\r
-\r
-  private static final int PREVIOUS_COMMIT_AUTHORS_LIMIT = 16; // Limit for previous commit authors\r
-\r
-  private final GitVcsApplicationSettings myAppSettings;\r
-  private State myState = new State();\r
-  \r
-  /**\r
-   * The way the local changes are saved before update if user has selected auto-stash\r
-   */\r
-  public enum UpdateChangesPolicy {\r
-    STASH,\r
-    SHELVE,\r
-  }\r
-\r
-  /**\r
-   * Kinds of SSH executable to be used with the git\r
-   */\r
-  public enum SshExecutable {\r
-    IDEA_SSH,\r
-    NATIVE_SSH,\r
-  }\r
-\r
-  public enum ConversionPolicy {\r
-    NONE, // No conversion is performed\r
-    CONVERT, // The files are converted to project line separators\r
-    ASK  // Show dialog and ask user what to do: convert files or leave unchanged.\r
-  }\r
-\r
-  public static class State {\r
-    public List<String> PREVIOUS_COMMIT_AUTHORS = new ArrayList<String>(); // The previously entered authors of the commit (up to {@value #PREVIOUS_COMMIT_AUTHORS_LIMIT})\r
-    public SshExecutable SSH_EXECUTABLE = SshExecutable.IDEA_SSH;\r
-    public UpdateChangesPolicy UPDATE_CHANGES_POLICY = UpdateChangesPolicy.STASH; // The policy that specifies how files are saved before update or rebase\r
-    public UpdateMethod UPDATE_TYPE = UpdateMethod.BRANCH_DEFAULT;\r
-    public ConversionPolicy LINE_SEPARATORS_CONVERSION = ConversionPolicy.ASK;\r
-    public boolean PUSH_AUTO_UPDATE = false;\r
-    public GitBranchSyncSetting SYNC_SETTING = GitBranchSyncSetting.NOT_DECIDED;\r
-    public String RECENT_GIT_ROOT_PATH = null;\r
-    public Map<String, String> RECENT_BRANCH_BY_REPOSITORY = new HashMap<String, String>();\r
-    public String RECENT_COMMON_BRANCH = null;\r
-    public boolean AUTO_COMMIT_ON_CHERRY_PICK = false;\r
-  }\r
-\r
-  public GitVcsSettings(GitVcsApplicationSettings appSettings) {\r
-    myAppSettings = appSettings;\r
-  }\r
-\r
-  public GitVcsApplicationSettings getAppSettings() {\r
-    return myAppSettings;\r
-  }\r
-  \r
-  public static GitVcsSettings getInstance(Project project) {\r
-    return PeriodicalTasksCloser.getInstance().safeGetService(project, GitVcsSettings.class);\r
-  }\r
-\r
-  public ConversionPolicy getLineSeparatorsConversion() {\r
-    return myState.LINE_SEPARATORS_CONVERSION;\r
-  }\r
-\r
-  public void setLineSeparatorsConversion(ConversionPolicy lineSeparatorsConversion) {\r
-    myState.LINE_SEPARATORS_CONVERSION = lineSeparatorsConversion;\r
-  }\r
-\r
-  public UpdateMethod getUpdateType() {\r
-    return myState.UPDATE_TYPE;\r
-  }\r
-\r
-  public void setUpdateType(UpdateMethod updateType) {\r
-    myState.UPDATE_TYPE = updateType;\r
-  }\r
-\r
-  @NotNull\r
-  public UpdateChangesPolicy updateChangesPolicy() {\r
-    return myState.UPDATE_CHANGES_POLICY;\r
-  }\r
-\r
-  public void setUpdateChangesPolicy(UpdateChangesPolicy value) {\r
-    myState.UPDATE_CHANGES_POLICY = value;\r
-  }\r
-\r
-  /**\r
-   * Save an author of the commit and make it the first one. If amount of authors exceeds the limit, remove least recently selected author.\r
-   *\r
-   * @param author an author to save\r
-   */\r
-  public void saveCommitAuthor(String author) {\r
-    myState.PREVIOUS_COMMIT_AUTHORS.remove(author);\r
-    while (myState.PREVIOUS_COMMIT_AUTHORS.size() >= PREVIOUS_COMMIT_AUTHORS_LIMIT) {\r
-      myState.PREVIOUS_COMMIT_AUTHORS.remove(myState.PREVIOUS_COMMIT_AUTHORS.size() - 1);\r
-    }\r
-    myState.PREVIOUS_COMMIT_AUTHORS.add(0, author);\r
-  }\r
-\r
-  public String[] getCommitAuthors() {\r
-    return ArrayUtil.toStringArray(myState.PREVIOUS_COMMIT_AUTHORS);\r
-  }\r
-\r
-  public State getState() {\r
-    return myState;\r
-  }\r
-\r
-  public void loadState(State state) {\r
-    myState = state;\r
-  }\r
-\r
-  public boolean isIdeaSsh() {\r
-    return myState.SSH_EXECUTABLE == SshExecutable.IDEA_SSH;\r
-  }\r
-\r
-  public void setIdeaSsh(boolean value) {\r
-    myState.SSH_EXECUTABLE = value ? SshExecutable.IDEA_SSH : SshExecutable.NATIVE_SSH;\r
-  }\r
-\r
-  public boolean autoUpdateIfPushRejected() {\r
-    return myState.PUSH_AUTO_UPDATE;\r
-  }\r
-\r
-  public void setAutoUpdateIfPushRejected(boolean autoUpdate) {\r
-    myState.PUSH_AUTO_UPDATE = autoUpdate;\r
-  }\r
-\r
-  @NotNull\r
-  public GitBranchSyncSetting getSyncSetting() {\r
-    return myState.SYNC_SETTING;\r
-  }\r
-\r
-  public void setSyncSetting(@NotNull GitBranchSyncSetting syncSetting) {\r
-    myState.SYNC_SETTING = syncSetting;\r
-  }\r
-\r
-  @Nullable\r
-  public String getRecentRootPath() {\r
-    return myState.RECENT_GIT_ROOT_PATH;\r
-  }\r
-\r
-  public void setRecentRoot(@NotNull String recentGitRootPath) {\r
-    myState.RECENT_GIT_ROOT_PATH = recentGitRootPath;\r
-  }\r
-\r
-  @NotNull\r
-  public Map<String, String> getRecentBranchesByRepository() {\r
-    return myState.RECENT_BRANCH_BY_REPOSITORY;\r
-  }\r
-\r
-  public void setRecentBranchOfRepository(@NotNull String repositoryPath, @NotNull String branch) {\r
-    myState.RECENT_BRANCH_BY_REPOSITORY.put(repositoryPath, branch);\r
-  }\r
-\r
-  @Nullable\r
-  public String getRecentCommonBranch() {\r
-    return myState.RECENT_COMMON_BRANCH;\r
-  }\r
-\r
-  public void setRecentCommonBranch(@NotNull String branch) {\r
-    myState.RECENT_COMMON_BRANCH = branch;\r
-  }\r
-\r
-  public void setAutoCommitOnCherryPick(boolean autoCommit) {\r
-    myState.AUTO_COMMIT_ON_CHERRY_PICK = autoCommit;\r
-  }\r
-\r
-  public boolean isAutoCommitOnCherryPick() {\r
-    return myState.AUTO_COMMIT_ON_CHERRY_PICK;\r
-  }\r
-\r
-}\r
+/*
+ * Copyright 2000-2012 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package git4idea.config;
+
+import com.intellij.lifecycle.PeriodicalTasksCloser;
+import com.intellij.openapi.components.PersistentStateComponent;
+import com.intellij.openapi.components.State;
+import com.intellij.openapi.components.Storage;
+import com.intellij.openapi.components.StoragePathMacros;
+import com.intellij.openapi.project.Project;
+import com.intellij.util.ArrayUtil;
+import git4idea.ui.branch.GitBranchSyncSetting;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Git VCS settings
+ */
+@State(name = "Git.Settings", storages = {@Storage(file = StoragePathMacros.WORKSPACE_FILE)})
+public class GitVcsSettings implements PersistentStateComponent<GitVcsSettings.State> {
+
+  private static final int PREVIOUS_COMMIT_AUTHORS_LIMIT = 16; // Limit for previous commit authors
+
+  private final GitVcsApplicationSettings myAppSettings;
+  private State myState = new State();
+  
+  /**
+   * The way the local changes are saved before update if user has selected auto-stash
+   */
+  public enum UpdateChangesPolicy {
+    STASH,
+    SHELVE,
+  }
+
+  public enum ConversionPolicy {
+    NONE, // No conversion is performed
+    CONVERT, // The files are converted to project line separators
+    ASK  // Show dialog and ask user what to do: convert files or leave unchanged.
+  }
+
+  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>();
+    // 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;
+    public ConversionPolicy LINE_SEPARATORS_CONVERSION = ConversionPolicy.ASK;
+    public boolean PUSH_AUTO_UPDATE = false;
+    public GitBranchSyncSetting SYNC_SETTING = GitBranchSyncSetting.NOT_DECIDED;
+    public String RECENT_GIT_ROOT_PATH = null;
+    public Map<String, String> RECENT_BRANCH_BY_REPOSITORY = new HashMap<String, String>();
+    public String RECENT_COMMON_BRANCH = null;
+    public boolean AUTO_COMMIT_ON_CHERRY_PICK = false;
+  }
+
+  public GitVcsSettings(GitVcsApplicationSettings appSettings) {
+    myAppSettings = appSettings;
+  }
+
+  public GitVcsApplicationSettings getAppSettings() {
+    return myAppSettings;
+  }
+  
+  public static GitVcsSettings getInstance(Project project) {
+    return PeriodicalTasksCloser.getInstance().safeGetService(project, GitVcsSettings.class);
+  }
+
+  public ConversionPolicy getLineSeparatorsConversion() {
+    return myState.LINE_SEPARATORS_CONVERSION;
+  }
+
+  public void setLineSeparatorsConversion(ConversionPolicy lineSeparatorsConversion) {
+    myState.LINE_SEPARATORS_CONVERSION = lineSeparatorsConversion;
+  }
+
+  public UpdateMethod getUpdateType() {
+    return myState.UPDATE_TYPE;
+  }
+
+  public void setUpdateType(UpdateMethod updateType) {
+    myState.UPDATE_TYPE = updateType;
+  }
+
+  @NotNull
+  public UpdateChangesPolicy updateChangesPolicy() {
+    return myState.UPDATE_CHANGES_POLICY;
+  }
+
+  public void setUpdateChangesPolicy(UpdateChangesPolicy value) {
+    myState.UPDATE_CHANGES_POLICY = value;
+  }
+
+  /**
+   * Save an author of the commit and make it the first one. If amount of authors exceeds the limit, remove least recently selected author.
+   *
+   * @param author an author to save
+   */
+  public void saveCommitAuthor(String author) {
+    myState.PREVIOUS_COMMIT_AUTHORS.remove(author);
+    while (myState.PREVIOUS_COMMIT_AUTHORS.size() >= PREVIOUS_COMMIT_AUTHORS_LIMIT) {
+      myState.PREVIOUS_COMMIT_AUTHORS.remove(myState.PREVIOUS_COMMIT_AUTHORS.size() - 1);
+    }
+    myState.PREVIOUS_COMMIT_AUTHORS.add(0, author);
+  }
+
+  public String[] getCommitAuthors() {
+    return ArrayUtil.toStringArray(myState.PREVIOUS_COMMIT_AUTHORS);
+  }
+
+  public State getState() {
+    return myState;
+  }
+
+  public void loadState(State state) {
+    myState = state;
+  }
+
+  public boolean autoUpdateIfPushRejected() {
+    return myState.PUSH_AUTO_UPDATE;
+  }
+
+  public void setAutoUpdateIfPushRejected(boolean autoUpdate) {
+    myState.PUSH_AUTO_UPDATE = autoUpdate;
+  }
+
+  @NotNull
+  public GitBranchSyncSetting getSyncSetting() {
+    return myState.SYNC_SETTING;
+  }
+
+  public void setSyncSetting(@NotNull GitBranchSyncSetting syncSetting) {
+    myState.SYNC_SETTING = syncSetting;
+  }
+
+  @Nullable
+  public String getRecentRootPath() {
+    return myState.RECENT_GIT_ROOT_PATH;
+  }
+
+  public void setRecentRoot(@NotNull String recentGitRootPath) {
+    myState.RECENT_GIT_ROOT_PATH = recentGitRootPath;
+  }
+
+  @NotNull
+  public Map<String, String> getRecentBranchesByRepository() {
+    return myState.RECENT_BRANCH_BY_REPOSITORY;
+  }
+
+  public void setRecentBranchOfRepository(@NotNull String repositoryPath, @NotNull String branch) {
+    myState.RECENT_BRANCH_BY_REPOSITORY.put(repositoryPath, branch);
+  }
+
+  @Nullable
+  public String getRecentCommonBranch() {
+    return myState.RECENT_COMMON_BRANCH;
+  }
+
+  public void setRecentCommonBranch(@NotNull String branch) {
+    myState.RECENT_COMMON_BRANCH = branch;
+  }
+
+  public void setAutoCommitOnCherryPick(boolean autoCommit) {
+    myState.AUTO_COMMIT_ON_CHERRY_PICK = autoCommit;
+  }
+
+  public boolean isAutoCommitOnCherryPick() {
+    return myState.AUTO_COMMIT_ON_CHERRY_PICK;
+  }
+
+}