Commit 56e80092 authored by Friedemann Kleint's avatar Friedemann Kleint
Browse files

VCS[git]: Environment settings.

Make GitClient::synchronousGit use the process environment.

Windows: Add a setting to fake a 'HOME' environment variable
(%HOMEDRIVE%%HOMEPATH%) to make msysgit look for its SSH-keys
there not only when run from git bash, but also from Qt Creator.
Useful in MinGw-setups, where git must not be in the path.
parent 12feb869
......@@ -1090,11 +1090,32 @@ QStringList GitClient::binary() const
#endif
}
// Determine a value for the HOME variable on Windows
// working around MSys git not finding it when run outside git bash
// (then looking for the SSH keys under "\program files\git").
QString GitClient::fakeWinHome(const QProcessEnvironment &e)
{
const QString homeDrive = e.value("HOMEDRIVE");
const QString homePath = e.value("HOMEPATH");
QTC_ASSERT(!homeDrive.isEmpty() && !homePath.isEmpty(), return QString())
return homeDrive + homePath;
}
QProcessEnvironment GitClient::processEnvironment() const
{
QProcessEnvironment environment = QProcessEnvironment::systemEnvironment();
if (m_settings.adoptPath)
environment.insert(QLatin1String("PATH"), m_settings.path);
#ifdef Q_OS_WIN
if (m_settings.winSetHomeEnvironment) {
const QString home = fakeWinHome(environment);
if (Constants::debug)
qDebug("Setting home '%s'", qPrintable(home));
environment.insert(QLatin1String("HOME"), home);
}
#endif // Q_OS_WIN
// Set up SSH and C locale (required by git using perl).
VCSBase::VCSBasePlugin::setProcessEnvironment(&environment, false);
return environment;
......@@ -1116,6 +1137,7 @@ Utils::SynchronousProcessResponse
args.append(gitArguments);
return VCSBase::VCSBasePlugin::runVCS(workingDirectory, executable, args,
m_settings.timeoutSeconds * 1000,
processEnvironment(),
flags, stdOutCodec);
}
......
......@@ -212,6 +212,7 @@ public:
QStringList binary() const; // Executable + basic arguments
QProcessEnvironment processEnvironment() const;
static QString fakeWinHome(const QProcessEnvironment &e);
static QString msgNoChangedFiles();
......@@ -279,7 +280,6 @@ private:
bool m_hasCachedGitVersion;
};
} // namespace Internal
} // namespace Git
......
......@@ -46,6 +46,7 @@ static const char promptToSubmitKeyC[] = "PromptForSubmit";
static const char omitAnnotationDateKeyC[] = "OmitAnnotationDate";
static const char spaceIgnorantBlameKeyC[] = "SpaceIgnorantBlame";
static const char diffPatienceKeyC[] = "DiffPatience";
static const char winSetHomeEnvironmentKeyC[] = "WinSetHomeEnvironment";
static const char gitkOptionsKeyC[] = "GitKOptions";
enum {
......@@ -69,7 +70,8 @@ GitSettings::GitSettings() :
promptToSubmit(true),
omitAnnotationDate(false),
spaceIgnorantBlame(true),
diffPatience(true)
diffPatience(true),
winSetHomeEnvironment(false)
{
}
......@@ -84,7 +86,8 @@ void GitSettings::fromSettings(QSettings *settings)
promptToSubmit = settings->value(QLatin1String(promptToSubmitKeyC), true).toBool();
omitAnnotationDate = settings->value(QLatin1String(omitAnnotationDateKeyC), false).toBool();
spaceIgnorantBlame = settings->value(QLatin1String(spaceIgnorantBlameKeyC), true).toBool();
diffPatience = settings->value(QLatin1String(diffPatienceKeyC), true).toBool();
diffPatience = settings->value(QLatin1String(diffPatienceKeyC), true).toBool();
winSetHomeEnvironment = settings->value(QLatin1String(winSetHomeEnvironmentKeyC), false).toBool();
gitkOptions = settings->value(QLatin1String(gitkOptionsKeyC)).toString();
settings->endGroup();
}
......@@ -101,6 +104,7 @@ void GitSettings::toSettings(QSettings *settings) const
settings->setValue(QLatin1String(omitAnnotationDateKeyC), omitAnnotationDate);
settings->setValue(QLatin1String(spaceIgnorantBlameKeyC), spaceIgnorantBlame);
settings->setValue(QLatin1String(diffPatienceKeyC), diffPatience);
settings->setValue(QLatin1String(winSetHomeEnvironmentKeyC), winSetHomeEnvironment);
settings->setValue(QLatin1String(gitkOptionsKeyC), gitkOptions);
settings->endGroup();
}
......@@ -111,7 +115,7 @@ bool GitSettings::equals(const GitSettings &s) const
&& timeoutSeconds == s.timeoutSeconds && promptToSubmit == s.promptToSubmit
&& pullRebase == s.pullRebase
&& omitAnnotationDate == s.omitAnnotationDate && spaceIgnorantBlame == s.spaceIgnorantBlame
&& diffPatience == s.diffPatience
&& diffPatience == s.diffPatience && winSetHomeEnvironment == s.winSetHomeEnvironment
&& gitkOptions == s.gitkOptions;
}
......
......@@ -60,6 +60,7 @@ struct GitSettings
bool omitAnnotationDate;
bool spaceIgnorantBlame;
bool diffPatience;
bool winSetHomeEnvironment;
QString gitkOptions;
};
......
......@@ -30,6 +30,7 @@
#include "settingspage.h"
#include "gitsettings.h"
#include "gitplugin.h"
#include "gitclient.h"
#include <vcsbase/vcsbaseconstants.h>
......@@ -37,6 +38,7 @@
#include <QtCore/QFileInfo>
#include <QtCore/QDebug>
#include <QtCore/QTextStream>
#include <QtCore/QProcessEnvironment>
#include <QtGui/QMessageBox>
namespace Git {
......@@ -47,6 +49,19 @@ SettingsPageWidget::SettingsPageWidget(QWidget *parent) :
{
m_ui.setupUi(this);
connect(m_ui.adoptButton, SIGNAL(clicked()), this, SLOT(setSystemPath()));
#ifdef Q_OS_WIN
const QByteArray currentHome = qgetenv("HOME");
const QString toolTip
= tr("Set the environment variable HOME to '%1'\n(%2).\n"
"This causes msysgit to look for the SSH-keys in that location\n"
"instead of its installation directory when run outside git bash.").
arg(GitClient::fakeWinHome(QProcessEnvironment::systemEnvironment()),
currentHome.isEmpty() ? tr("not currently set") :
tr("currently set to '%1'").arg(QString::fromLocal8Bit(currentHome)));
m_ui.winHomeCheckBox->setToolTip(toolTip);
#else
m_ui.winHomeCheckBox->setVisible(false);
#endif
}
GitSettings SettingsPageWidget::settings() const
......@@ -61,6 +76,7 @@ GitSettings SettingsPageWidget::settings() const
rc.omitAnnotationDate = m_ui.omitAnnotationDataCheckBox->isChecked();
rc.spaceIgnorantBlame = m_ui.spaceIgnorantBlameCheckBox->isChecked();
rc.diffPatience = m_ui.diffPatienceCheckBox->isChecked();
rc.winSetHomeEnvironment = m_ui.winHomeCheckBox->isChecked();
rc.gitkOptions = m_ui.gitkOptionsLineEdit->text().trimmed();
return rc;
}
......@@ -76,6 +92,7 @@ void SettingsPageWidget::setSettings(const GitSettings &s)
m_ui.omitAnnotationDataCheckBox->setChecked(s.omitAnnotationDate);
m_ui.spaceIgnorantBlameCheckBox->setChecked(s.spaceIgnorantBlame);
m_ui.diffPatienceCheckBox->setChecked(s.diffPatience);
m_ui.winHomeCheckBox->setChecked(s.winSetHomeEnvironment);
m_ui.gitkOptionsLineEdit->setText(s.gitkOptions);
}
......
......@@ -36,6 +36,13 @@
</item>
</layout>
</item>
<item>
<widget class="QCheckBox" name="winHomeCheckBox">
<property name="text">
<string>Set &quot;HOME&quot; environment variable</string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="noteHorizontalLayout">
<item>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment