2 * Copyright 2000-2012 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package git4idea.config;
18 import com.intellij.openapi.components.*;
19 import com.intellij.openapi.util.SystemInfo;
20 import org.jetbrains.annotations.NonNls;
21 import org.jetbrains.annotations.NotNull;
22 import org.jetbrains.annotations.Nullable;
27 * The application wide settings for the git
30 name = "Git.Application.Settings",
31 storages = {@Storage(file = StoragePathMacros.APP_CONFIG + "/vcs.xml")})
32 public class GitVcsApplicationSettings implements PersistentStateComponent<GitVcsApplicationSettings.State> {
34 @NonNls static final String[] DEFAULT_WINDOWS_PATHS = {"C:\\cygwin\\bin", "C:\\Program Files\\Git\\bin", "C:\\Program Files (x86)\\Git\\bin"};
35 @NonNls static final String[] DEFAULT_UNIX_PATHS = {"/usr/local/bin", "/usr/bin", "/opt/local/bin", "/opt/bin", "/usr/local/git/bin"};
36 @NonNls static final String DEFAULT_WINDOWS_GIT = "git.exe";
37 @NonNls static final String DEFAULT_UNIX_GIT = "git";
39 private State myState = new State();
42 * Kinds of SSH executable to be used with the git
44 public enum SshExecutable {
49 public static class State {
50 public String myPathToGit = null;
51 public SshExecutable SSH_EXECUTABLE = null;
54 public static GitVcsApplicationSettings getInstance() {
55 return ServiceManager.getService(GitVcsApplicationSettings.class);
59 public State getState() {
63 public void loadState(State state) {
68 * @return the default executable name depending on the platform
71 public String defaultGit() {
72 if (myState.myPathToGit == null) {
75 if (SystemInfo.isWindows) {
76 program = DEFAULT_WINDOWS_GIT;
77 paths = DEFAULT_WINDOWS_PATHS;
80 program = DEFAULT_UNIX_GIT;
81 paths = DEFAULT_UNIX_PATHS;
83 for (String p : paths) {
84 File f = new File(p, program);
86 myState.myPathToGit = f.getAbsolutePath();
90 if (myState.myPathToGit == null) { // otherwise, hope it's in $PATH
91 myState.myPathToGit = program;
94 return myState.myPathToGit;
98 public String getPathToGit() {
99 return myState.myPathToGit == null ? defaultGit() : myState.myPathToGit;
102 public void setPathToGit(String pathToGit) {
103 myState.myPathToGit = pathToGit;
106 public void setIdeaSsh(@NotNull SshExecutable executable) {
107 myState.SSH_EXECUTABLE = executable;
111 SshExecutable getIdeaSsh() {
112 return myState.SSH_EXECUTABLE;