Enhance git pre-commit user.name check for old Gits without %HOME%

On Windows if %HOME% is not defined and Git is started via git.exe (not git.cmd), Git 1.7.0.2 and older doesn't define %HOME% properly.
 We used to set up %HOME% := %USERPROFILE%, but it is bad practice (IDEA-76150).
 Now just warn the user to let him update Git or set up %HOME% manually.
This commit is contained in:
Kirill Likhodedov
2012-01-27 18:26:40 +04:00
parent f2a059c44c
commit 35ffe7e82c
2 changed files with 26 additions and 3 deletions
@@ -30,6 +30,8 @@ import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.util.PairConsumer;
import git4idea.GitVcs;
import git4idea.config.GitConfigUtil;
import git4idea.config.GitVersion;
import git4idea.config.GitVersionSpecialty;
import git4idea.i18n.GitBundle;
import git4idea.repo.GitRepository;
import git4idea.repo.GitRepositoryManager;
@@ -82,10 +84,13 @@ public class GitCheckinHandlerFactory extends VcsCheckinHandlerFactory {
private ReturnResult checkUserName() {
Project project = myPanel.getProject();
GitVcs vcs = GitVcs.getInstance(project);
assert vcs != null;
Collection<VirtualFile> notDefined = new ArrayList<VirtualFile>();
Map<VirtualFile, Pair<String, String>> defined = new HashMap<VirtualFile, Pair<String, String>>();
Collection<VirtualFile> allRoots = new ArrayList<VirtualFile>(Arrays.asList(
ProjectLevelVcsManager.getInstance(project).getRootsUnderVcs(GitVcs.getInstance(project))));
ProjectLevelVcsManager.getInstance(project).getRootsUnderVcs(vcs)));
Collection<VirtualFile> affectedRoots = myPanel.getRoots();
for (VirtualFile root : affectedRoots) {
@@ -110,6 +115,17 @@ public class GitCheckinHandlerFactory extends VcsCheckinHandlerFactory {
return ReturnResult.COMMIT;
}
GitVersion version = vcs.getVersion();
if (System.getenv("HOME") == null && GitVersionSpecialty.DOESNT_DEFINE_HOME_ENV_VAR.existsIn(version)) {
Messages.showErrorDialog(project,
"You are using Git " + version + " which doesn't define %HOME% environment variable properly.\n" +
"Consider updating Git to a newer version " +
"or define %HOME% to point to the place where the global .gitconfig is stored \n" +
"(it is usually %USERPROFILE% or %HOMEDRIVE%%HOMEPATH%).",
"HOME Variable Is Not Defined");
return ReturnResult.CANCEL;
}
if (defined.isEmpty() && allRoots.size() > affectedRoots.size()) {
allRoots.removeAll(affectedRoots);
for (VirtualFile root : allRoots) {
@@ -15,6 +15,7 @@
*/
package git4idea.config;
import com.intellij.openapi.util.SystemInfo;
import org.jetbrains.annotations.NotNull;
/**
@@ -74,10 +75,16 @@ public enum GitVersionSpecialty {
*/
KNOWS_STATUS_PORCELAIN {
@Override
public boolean existsIn(@NotNull GitVersion
version) {
public boolean existsIn(@NotNull GitVersion version) {
return version.isLaterOrEqual(new GitVersion(1, 7, 0, 0));
}
},
DOESNT_DEFINE_HOME_ENV_VAR {
@Override
public boolean existsIn(@NotNull GitVersion version) {
return SystemInfo.isWindows && version.isOlderOrEqual(new GitVersion(1, 7, 0, 2));
}
};
public abstract boolean existsIn(@NotNull GitVersion version);