Git: Prepend to PATH instead of replacing it

Change-Id: Ia6d783e97d7f4c80a3838b0167dcdcfce5fe4a6e
Reviewed-by: Tobias Hunger <tobias.hunger@nokia.com>
This commit is contained in:
Orgad Shaneh
2012-01-27 09:52:06 +02:00
committed by Tobias Hunger
parent e2ace515e2
commit d3f889df7d
6 changed files with 11 additions and 33 deletions

View File

@@ -1408,8 +1408,12 @@ QProcessEnvironment GitClient::processEnvironment() const
{ {
QProcessEnvironment environment = QProcessEnvironment::systemEnvironment(); QProcessEnvironment environment = QProcessEnvironment::systemEnvironment();
if (settings()->boolValue(GitSettings::adoptPathKey)) QString gitPath = settings()->stringValue(GitSettings::pathKey);
environment.insert(QLatin1String("PATH"), settings()->stringValue(GitSettings::pathKey)); if (!gitPath.isEmpty()) {
gitPath += Utils::SynchronousProcess::pathSeparator();
gitPath += environment.value(QLatin1String("PATH"));
environment.insert(QLatin1String("PATH"), gitPath);
}
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
if (settings()->boolValue(GitSettings::winSetHomeEnvironmentKey)) if (settings()->boolValue(GitSettings::winSetHomeEnvironmentKey))
environment.insert(QLatin1String("HOME"), QDir::toNativeSeparators(QDir::homePath())); environment.insert(QLatin1String("HOME"), QDir::toNativeSeparators(QDir::homePath()));
@@ -1620,7 +1624,7 @@ bool GitClient::tryLauchingGitK(const QProcessEnvironment &env,
// This should always use QProcess::startDetached (as not to kill // This should always use QProcess::startDetached (as not to kill
// the child), but that does not have an environment parameter. // the child), but that does not have an environment parameter.
bool success = false; bool success = false;
if (settings()->boolValue(GitSettings::adoptPathKey)) { if (!settings()->stringValue(GitSettings::pathKey).isEmpty()) {
QProcess *process = new QProcess(this); QProcess *process = new QProcess(this);
process->setWorkingDirectory(workingDirectory); process->setWorkingDirectory(workingDirectory);
process->setProcessEnvironment(env); process->setProcessEnvironment(env);

View File

@@ -39,7 +39,6 @@
namespace Git { namespace Git {
namespace Internal { namespace Internal {
const QLatin1String GitSettings::adoptPathKey("SysEnv");
const QLatin1String GitSettings::pathKey("Path"); const QLatin1String GitSettings::pathKey("Path");
const QLatin1String GitSettings::pullRebaseKey("PullRebase"); const QLatin1String GitSettings::pullRebaseKey("PullRebase");
const QLatin1String GitSettings::omitAnnotationDateKey("OmitAnnotationDate"); const QLatin1String GitSettings::omitAnnotationDateKey("OmitAnnotationDate");
@@ -61,7 +60,6 @@ GitSettings::GitSettings()
#else #else
declareKey(timeoutKey, 30); declareKey(timeoutKey, 30);
#endif #endif
declareKey(adoptPathKey, false);
declareKey(pathKey, QString()); declareKey(pathKey, QString());
declareKey(pullRebaseKey, false); declareKey(pullRebaseKey, false);
declareKey(omitAnnotationDateKey, false); declareKey(omitAnnotationDateKey, false);
@@ -87,7 +85,7 @@ QString GitSettings::gitBinaryPath(bool *ok, QString *errorMessage) const
const QString binary = stringValue(binaryPathKey); const QString binary = stringValue(binaryPathKey);
QString currentPath = stringValue(pathKey); QString currentPath = stringValue(pathKey);
// Easy, git is assumed to be elsewhere accessible // Easy, git is assumed to be elsewhere accessible
if (!boolValue(adoptPathKey)) if (currentPath.isEmpty())
currentPath = QString::fromLocal8Bit(qgetenv("PATH")); currentPath = QString::fromLocal8Bit(qgetenv("PATH"));
// Search in path? // Search in path?
m_binaryPath = Utils::SynchronousProcess::locateBinary(currentPath, binary); m_binaryPath = Utils::SynchronousProcess::locateBinary(currentPath, binary);

View File

@@ -46,7 +46,6 @@ class GitSettings : public VcsBase::VcsBaseClientSettings
public: public:
GitSettings(); GitSettings();
static const QLatin1String adoptPathKey;
static const QLatin1String pathKey; static const QLatin1String pathKey;
static const QLatin1String pullRebaseKey; static const QLatin1String pullRebaseKey;
static const QLatin1String omitAnnotationDateKey; static const QLatin1String omitAnnotationDateKey;

View File

@@ -52,7 +52,6 @@ SettingsPageWidget::SettingsPageWidget(QWidget *parent) :
QWidget(parent) QWidget(parent)
{ {
m_ui.setupUi(this); m_ui.setupUi(this);
connect(m_ui.adoptButton, SIGNAL(clicked()), this, SLOT(setSystemPath()));
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
const QByteArray currentHome = qgetenv("HOME"); const QByteArray currentHome = qgetenv("HOME");
const QString toolTip const QString toolTip
@@ -72,8 +71,6 @@ GitSettings SettingsPageWidget::settings() const
{ {
GitSettings rc; GitSettings rc;
rc.setValue(GitSettings::pathKey, m_ui.pathLineEdit->text()); rc.setValue(GitSettings::pathKey, m_ui.pathLineEdit->text());
rc.setValue(GitSettings::adoptPathKey, m_ui.environmentGroupBox->isChecked()
&& !rc.stringValue(GitSettings::pathKey).isEmpty());
rc.setValue(GitSettings::logCountKey, m_ui.logCountSpinBox->value()); rc.setValue(GitSettings::logCountKey, m_ui.logCountSpinBox->value());
rc.setValue(GitSettings::timeoutKey, m_ui.timeoutSpinBox->value()); rc.setValue(GitSettings::timeoutKey, m_ui.timeoutSpinBox->value());
rc.setValue(GitSettings::pullRebaseKey, m_ui.pullRebaseCheckBox->isChecked()); rc.setValue(GitSettings::pullRebaseKey, m_ui.pullRebaseCheckBox->isChecked());
@@ -85,7 +82,6 @@ GitSettings SettingsPageWidget::settings() const
void SettingsPageWidget::setSettings(const GitSettings &s) void SettingsPageWidget::setSettings(const GitSettings &s)
{ {
m_ui.environmentGroupBox->setChecked(s.boolValue(GitSettings::adoptPathKey));
m_ui.pathLineEdit->setText(s.stringValue(GitSettings::pathKey)); m_ui.pathLineEdit->setText(s.stringValue(GitSettings::pathKey));
m_ui.logCountSpinBox->setValue(s.intValue(GitSettings::logCountKey)); m_ui.logCountSpinBox->setValue(s.intValue(GitSettings::logCountKey));
m_ui.timeoutSpinBox->setValue(s.intValue(GitSettings::timeoutKey)); m_ui.timeoutSpinBox->setValue(s.intValue(GitSettings::timeoutKey));
@@ -95,17 +91,11 @@ void SettingsPageWidget::setSettings(const GitSettings &s)
m_ui.gitkOptionsLineEdit->setText(s.stringValue(GitSettings::gitkOptionsKey)); m_ui.gitkOptionsLineEdit->setText(s.stringValue(GitSettings::gitkOptionsKey));
} }
void SettingsPageWidget::setSystemPath()
{
m_ui.pathLineEdit->setText(QLatin1String(qgetenv("PATH")));
}
QString SettingsPageWidget::searchKeywords() const QString SettingsPageWidget::searchKeywords() const
{ {
QString rc; QString rc;
QLatin1Char sep(' '); QLatin1Char sep(' ');
QTextStream(&rc) QTextStream(&rc)
<< sep << m_ui.environmentGroupBox->title()
<< sep << m_ui.pathlabel->text() << sep << m_ui.pathlabel->text()
<< sep << m_ui.winHomeCheckBox->text() << sep << m_ui.winHomeCheckBox->text()
<< sep << m_ui.groupBox->title() << sep << m_ui.groupBox->title()

View File

@@ -59,9 +59,6 @@ public:
QString searchKeywords() const; QString searchKeywords() const;
private slots:
void setSystemPath();
private: private:
Ui::SettingsPage m_ui; Ui::SettingsPage m_ui;
}; };

View File

@@ -12,34 +12,24 @@
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout"> <layout class="QVBoxLayout" name="verticalLayout">
<item> <item>
<widget class="QGroupBox" name="environmentGroupBox"> <widget class="QGroupBox" name="configurationGroupBox">
<property name="enabled"> <property name="enabled">
<bool>true</bool> <bool>true</bool>
</property> </property>
<property name="title"> <property name="title">
<string>Customize Environment:</string> <string>Configuration</string>
</property>
<property name="checkable">
<bool>true</bool>
</property> </property>
<layout class="QGridLayout" name="gridLayout_2"> <layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0"> <item row="0" column="0">
<widget class="QLabel" name="pathlabel"> <widget class="QLabel" name="pathlabel">
<property name="text"> <property name="text">
<string>PATH:</string> <string>Prepend to PATH:</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="0" column="1"> <item row="0" column="1">
<widget class="QLineEdit" name="pathLineEdit"/> <widget class="QLineEdit" name="pathLineEdit"/>
</item> </item>
<item row="0" column="2">
<widget class="QPushButton" name="adoptButton">
<property name="text">
<string>From System</string>
</property>
</widget>
</item>
<item row="1" column="0" colspan="3"> <item row="1" column="0" colspan="3">
<widget class="QCheckBox" name="winHomeCheckBox"> <widget class="QCheckBox" name="winHomeCheckBox">
<property name="text"> <property name="text">