1 package git4idea
.config
;
3 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance
4 * with the License. You may obtain a copy of the License at:
6 * http://www.apache.org/licenses/LICENSE-2.0
8 * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
9 * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for
10 * the specific language governing permissions and limitations under the License.
12 * Copyright 2007 Decentrix Inc
13 * Copyright 2007 Aspiro AS
14 * Copyright 2008 MQSoftware
15 * Copyright 2008 JetBrains s.r.o.
16 * Copyright 2000-2009 JetBrains s.r.o.
18 * Authors: gevession, Erlend Simonsen & Mark Scott
20 * This code was originally derived from the MKS & Mercurial IDEA VCS plugins
23 import com
.intellij
.openapi
.application
.ApplicationManager
;
24 import com
.intellij
.openapi
.components
.PersistentStateComponent
;
25 import com
.intellij
.openapi
.components
.ServiceManager
;
26 import com
.intellij
.openapi
.components
.State
;
27 import com
.intellij
.openapi
.components
.Storage
;
28 import com
.intellij
.openapi
.progress
.ProcessCanceledException
;
29 import com
.intellij
.openapi
.project
.Project
;
30 import com
.intellij
.openapi
.util
.Computable
;
31 import com
.intellij
.openapi
.util
.SystemInfo
;
32 import com
.intellij
.util
.xmlb
.XmlSerializerUtil
;
33 import org
.jetbrains
.annotations
.NonNls
;
36 import java
.util
.Arrays
;
37 import java
.util
.LinkedList
;
43 name
= "Git.Settings",
46 file
= "$WORKSPACE_FILE$")})
47 public class GitVcsSettings
implements PersistentStateComponent
<GitVcsSettings
> {
51 private static final SshExecutable DEFAULT_SSH
= SshExecutable
.IDEA_SSH
;
53 * the default cygwin executable
55 @NonNls private static final String
[] DEFAULT_WINDOWS_PATHS
=
56 {"C:\\cygwin\\bin", "C:\\Program Files\\Git\\bin", "C:\\Program Files (x86)\\Git\\bin"};
58 * Windows executable name
60 @NonNls private static final String DEFAULT_WINDOWS_GIT
= "git.exe";
64 @NonNls private static final String
[] DEFAULT_UNIX_PATHS
= {"/usr/local/bin", "/usr/bin", "/opt/local/bin", "/opt/bin"};
66 * UNIX executable name
68 @NonNls private static final String DEFAULT_UNIX_GIT
= "git";
71 * The default executable for GIT
73 public String GIT_EXECUTABLE
= defaultGit();
75 * The previously entered authors of the commit (up to {@value #PREVIOUS_COMMIT_AUTHORS_LIMIT})
77 public String
[] PREVIOUS_COMMIT_AUTHORS
= {};
79 * Limit for previous commit authors
81 public static final int PREVIOUS_COMMIT_AUTHORS_LIMIT
= 16;
83 * Checkout includes tags
85 public Boolean CHECKOUT_INCLUDE_TAGS
;
87 * IDEA SSH should be used instead of native SSH.
89 public SshExecutable SSH_EXECUTABLE
= DEFAULT_SSH
;
91 * True if stash/unstash operation should be performed before update.
93 public boolean UPDATE_STASH
= true;
95 * The type of update operation to perform
97 public UpdateType UPDATE_TYPE
= UpdateType
.BRANCH_DEFAULT
;
100 * Save an author of the commit and make it the first one. If amount of authors exceeds the limit, remove least recently selected author.
102 * @param author an author to save
104 public void saveCommitAuthor(String author
) {
105 LinkedList
<String
> authors
= new LinkedList
<String
>(Arrays
.asList(PREVIOUS_COMMIT_AUTHORS
));
106 authors
.remove(author
);
107 while (authors
.size() >= PREVIOUS_COMMIT_AUTHORS_LIMIT
) {
108 authors
.removeLast();
110 authors
.addFirst(author
);
111 PREVIOUS_COMMIT_AUTHORS
= authors
.toArray(new String
[authors
.size()]);
117 public GitVcsSettings
getState() {
124 public void loadState(GitVcsSettings gitVcsSettings
) {
125 XmlSerializerUtil
.copyBean(gitVcsSettings
, this);
129 * Get git setting for the project
131 * @param project a context project
132 * @return the git settings
134 public static GitVcsSettings
getInstance(Project project
) {
135 return ServiceManager
.getService(project
, GitVcsSettings
.class);
139 * Get instance with checked read action
141 * @param project the project to get setting for
142 * @return the settings object
144 public static GitVcsSettings
getInstanceChecked(final Project project
) {
145 return ApplicationManager
.getApplication().runReadAction(new Computable
<GitVcsSettings
>() {
146 public GitVcsSettings
compute() {
147 if (project
.isDisposed()) throw new ProcessCanceledException();
148 return ServiceManager
.getService(project
, GitVcsSettings
.class);
154 * @return the default executable name depending on the platform
156 private static String
defaultGit() {
159 if (SystemInfo
.isWindows
) {
160 program
= DEFAULT_WINDOWS_GIT
;
161 paths
= DEFAULT_WINDOWS_PATHS
;
164 program
= DEFAULT_UNIX_GIT
;
165 paths
= DEFAULT_UNIX_PATHS
;
167 for (String p
: paths
) {
168 File f
= new File(p
, program
);
170 return f
.getAbsolutePath();
173 return program
; // otherwise, hope it's in $PATH
177 * @return true if IDEA ssh should be used
179 public boolean isIdeaSsh() {
180 return (SSH_EXECUTABLE
== null ? DEFAULT_SSH
: SSH_EXECUTABLE
) == SshExecutable
.IDEA_SSH
;
184 * @return true if IDEA ssh should be used
186 public static boolean isDefaultIdeaSsh() {
187 return DEFAULT_SSH
== SshExecutable
.IDEA_SSH
;
193 * @param value the value to set
195 public void setIdeaSsh(boolean value
) {
196 SSH_EXECUTABLE
= value ? SshExecutable
.IDEA_SSH
: SshExecutable
.NATIVE_SSH
;
200 * Kinds of SSH executable to be used with the git
202 public enum SshExecutable
{
204 * SSH provided by IDEA
213 * The type of update to perform
215 public enum UpdateType
{
216 /** Use default specified in the config file for the branch */
218 /** Merge fetched commits with local branch */
220 /** Rebase local commits upon the fetched branch*/