Commit 69e022d1 authored by Orgad Shaneh's avatar Orgad Shaneh Committed by Tobias Hunger

Git: Fix binary lookup with path setting

Task-number: QTCREATORBUG-7889

Change-Id: I251ef68e8dbb0a70565708053e368db89d5999e5
Reviewed-by: default avatarTobias Hunger <tobias.hunger@digia.com>
parent 6c436988
......@@ -30,14 +30,11 @@
#include "gitsettings.h"
#include <utils/synchronousprocess.h>
#include <QCoreApplication>
namespace Git {
namespace Internal {
const QLatin1String GitSettings::pathKey("Path");
const QLatin1String GitSettings::pullRebaseKey("PullRebase");
const QLatin1String GitSettings::omitAnnotationDateKey("OmitAnnotationDate");
const QLatin1String GitSettings::ignoreSpaceChangesInDiffKey("SpaceIgnorantDiff");
......@@ -59,7 +56,6 @@ GitSettings::GitSettings()
#else
declareKey(timeoutKey, 30);
#endif
declareKey(pathKey, QString());
declareKey(pullRebaseKey, false);
declareKey(omitAnnotationDateKey, false);
declareKey(ignoreSpaceChangesInDiffKey, true);
......@@ -81,33 +77,21 @@ QString GitSettings::gitBinaryPath(bool *ok, QString *errorMessage) const
if (errorMessage)
errorMessage->clear();
if (m_binaryPath.isEmpty()) {
const QString binary = binaryPath();
QString currentPath = stringValue(pathKey);
QString systemPath = QString::fromLocal8Bit(qgetenv("PATH"));
if (!systemPath.isEmpty()) {
if (!currentPath.isEmpty())
currentPath.append(Utils::SynchronousProcess::pathSeparator());
currentPath.append(systemPath);
}
// Search in path?
m_binaryPath = Utils::SynchronousProcess::locateBinary(currentPath, binary);
if (m_binaryPath.isEmpty()) {
if (ok)
*ok = false;
if (errorMessage)
*errorMessage = QCoreApplication::translate("Git::Internal::GitSettings",
"The binary '%1' could not be located in the path '%2'")
.arg(binary, currentPath);
}
QString binPath = binaryPath();
if (binPath.isEmpty()) {
if (ok)
*ok = false;
if (errorMessage)
*errorMessage = QCoreApplication::translate("Git::Internal::GitSettings",
"The binary '%1' could not be located in the path '%2'")
.arg(stringValue(binaryPathKey), stringValue(pathKey));
}
return m_binaryPath;
return binPath;
}
GitSettings &GitSettings::operator = (const GitSettings &s)
{
VcsBaseClientSettings::operator =(s);
m_binaryPath.clear();
return *this;
}
......
......@@ -44,7 +44,6 @@ class GitSettings : public VcsBase::VcsBaseClientSettings
public:
GitSettings();
static const QLatin1String pathKey;
static const QLatin1String pullRebaseKey;
static const QLatin1String omitAnnotationDateKey;
static const QLatin1String ignoreSpaceChangesInDiffKey;
......@@ -59,9 +58,6 @@ public:
QString gitBinaryPath(bool *ok = 0, QString *errorMessage = 0) const;
GitSettings &operator = (const GitSettings &s);
private:
mutable QString m_binaryPath;
};
} // namespace Internal
......
......@@ -31,6 +31,7 @@
#include "vcsbaseclientsettings.h"
#include <utils/environment.h>
#include <utils/synchronousprocess.h>
#include <QSettings>
......@@ -175,7 +176,7 @@ public:
QHash<QString, SettingValue> m_valueHash;
QVariantHash m_defaultValueHash;
QString m_settingsGroup;
QString m_binaryFullPath;
mutable QString m_binaryFullPath;
};
} // namespace Internal
......@@ -194,6 +195,7 @@ const QLatin1String VcsBaseClientSettings::userEmailKey("UserEmail");
const QLatin1String VcsBaseClientSettings::logCountKey("LogCount");
const QLatin1String VcsBaseClientSettings::promptOnSubmitKey("PromptOnSubmit");
const QLatin1String VcsBaseClientSettings::timeoutKey("Timeout");
const QLatin1String VcsBaseClientSettings::pathKey("Path");
VcsBaseClientSettings::VcsBaseClientSettings() :
d(new Internal::VcsBaseClientSettingsPrivate)
......@@ -204,6 +206,7 @@ VcsBaseClientSettings::VcsBaseClientSettings() :
declareKey(logCountKey, 100);
declareKey(promptOnSubmitKey, true);
declareKey(timeoutKey, 30);
declareKey(pathKey, QString());
}
VcsBaseClientSettings::VcsBaseClientSettings(const VcsBaseClientSettings &other) :
......@@ -332,8 +335,7 @@ void VcsBaseClientSettings::setValue(const QString &key, const QVariant &v)
{
if (SettingValue::isUsableVariantType(valueType(key))) {
d->m_valueHash.insert(key, SettingValue(v));
if (key == binaryPathKey)
d->m_binaryFullPath = Utils::Environment::systemEnvironment().searchInPath(v.toString());
d->m_binaryFullPath.clear();
}
}
......@@ -346,6 +348,11 @@ QVariant::Type VcsBaseClientSettings::valueType(const QString &key) const
QString VcsBaseClientSettings::binaryPath() const
{
if (d->m_binaryFullPath.isEmpty()) {
d->m_binaryFullPath = Utils::Environment::systemEnvironment().searchInPath(
stringValue(binaryPathKey), stringValue(pathKey).split(
Utils::SynchronousProcess::pathSeparator()));
}
return d->m_binaryFullPath;
}
......
......@@ -54,6 +54,7 @@ public:
static const QLatin1String logCountKey;
static const QLatin1String promptOnSubmitKey;
static const QLatin1String timeoutKey; // Seconds
static const QLatin1String pathKey;
VcsBaseClientSettings();
VcsBaseClientSettings(const VcsBaseClientSettings &other);
......
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