Commit 54db8772 authored by Orgad Shaneh's avatar Orgad Shaneh Committed by Orgad Shaneh
Browse files

Git: Factor out resolving of bin directory on Windows



Change-Id: Ifbafa0f5cb8329faedfd1da3674b87e46001acc3
Reviewed-by: default avatarFriedemann Kleint <Friedemann.Kleint@digia.com>
Reviewed-by: default avatarTobias Hunger <tobias.hunger@digia.com>
parent 36d2f47d
......@@ -73,14 +73,9 @@ static inline QString detectSsh()
if (!ssh.isEmpty())
return ssh;
if (Utils::HostOsInfo::isWindowsHost()) { // Windows: Use ssh.exe from git if it cannot be found.
const QString git = GerritPlugin::gitBinary();
if (!git.isEmpty()) {
// Is 'git\cmd' in the path (folder containing .bats)?
QString path = QFileInfo(git).absolutePath();
if (path.endsWith(QLatin1String("cmd"), Qt::CaseInsensitive))
path.replace(path.size() - 3, 3, QLatin1String("bin"));
ssh = path + QLatin1Char('/') + QLatin1String(defaultSshC);
}
Utils::FileName path = GerritPlugin::gitBinDirectory();
if (!path.isEmpty())
ssh = path.appendPath(QLatin1String(defaultSshC)).toString();
}
return ssh;
}
......
......@@ -399,6 +399,11 @@ QString GerritPlugin::gitBinary()
return git;
}
Utils::FileName GerritPlugin::gitBinDirectory()
{
return gitClient()->gitBinDirectory();
}
// Find the branch of a repository.
QString GerritPlugin::branch(const QString &repository)
{
......
......@@ -30,6 +30,8 @@
#ifndef GERRIT_INTERNAL_GERRITPLUGIN_H
#define GERRIT_INTERNAL_GERRITPLUGIN_H
#include <utils/fileutils.h>
#include <QObject>
#include <QPointer>
#include <QSharedPointer>
......@@ -62,6 +64,7 @@ public:
bool initialize(Core::ActionContainer *ac);
static QString gitBinary();
static Utils::FileName gitBinDirectory();
static QString branch(const QString &repository);
void addToLocator(Core::CommandLocator *locator);
void push(const QString &topLevel);
......
......@@ -2636,6 +2636,24 @@ bool GitClient::launchGitGui(const QString &workingDirectory) {
return success;
}
Utils::FileName GitClient::gitBinDirectory()
{
const QString git = gitBinaryPath();
if (git.isEmpty())
return Utils::FileName();
// Is 'git\cmd' in the path (folder containing .bats)?
QString path = QFileInfo(git).absolutePath();
// Git for Windows (msysGit) has git and gitk redirect executables in {setup dir}/cmd
// and the real binaries are in {setup dir}/bin. If cmd is configured in PATH
// or in Git settings, return bin instead.
if (Utils::HostOsInfo::isWindowsHost()
&& path.endsWith(QLatin1String("/cmd"), Utils::HostOsInfo::fileNameCaseSensitivity())) {
path.replace(path.size() - 3, 3, QLatin1String("bin"));
}
return Utils::FileName::fromString(path);
}
QString GitClient::gitBinaryPath(bool *ok, QString *errorMessage) const
{
return settings()->gitBinaryPath(ok, errorMessage);
......
......@@ -35,6 +35,8 @@
#include <coreplugin/editormanager/ieditor.h>
#include <utils/fileutils.h>
#include <QFutureSynchronizer>
#include <QObject>
#include <QString>
......@@ -315,6 +317,7 @@ public:
void launchGitK(const QString &workingDirectory, const QString &fileName);
void launchGitK(const QString &workingDirectory) { launchGitK(workingDirectory, QString()); }
bool launchGitGui(const QString &workingDirectory);
Utils::FileName gitBinDirectory();
void launchRepositoryBrowser(const QString &workingDirectory);
......
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