From ffbdfb883a3ccf4afd20997de06d48e368b87683 Mon Sep 17 00:00:00 2001 From: Orgad Shaneh Date: Mon, 27 Feb 2017 17:22:46 +0200 Subject: [PATCH] Gerrit: Improve curl detection Until Git for Windows 2.12.0, curl was shipped twice - a MinGW version in mingw{32,64}/bin, and MSYS2 version in usr/bin[1]. On 2.12.0, the MSYS2 version was removed, leaving only MinGW. The plugin only searches for curl in usr/bin, so it is clearly broken with 2.12. There is no reason to add mingw*/bin to GitClient::gitBinDirectory() (and return a list), because there are no other useful tools there. The other tools that use gitBinDirectory are patch and ssh, which are both in usr/bin. [1] https://github.com/git-for-windows/git/issues/1069 Change-Id: I5eb5fa727fa384835792c59fd018fdfa31594927 Reviewed-by: Tobias Hunger --- src/plugins/git/gerrit/gerritparameters.cpp | 31 ++++++++++++++++----- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/src/plugins/git/gerrit/gerritparameters.cpp b/src/plugins/git/gerrit/gerritparameters.cpp index 7a05ac053f1..3b70ab4a87e 100644 --- a/src/plugins/git/gerrit/gerritparameters.cpp +++ b/src/plugins/git/gerrit/gerritparameters.cpp @@ -30,6 +30,7 @@ #include #include +#include #include #include #include @@ -59,14 +60,30 @@ static inline QString detectApp(const char *defaultExe) { const QString defaultApp = HostOsInfo::withExecutableSuffix(QLatin1String(defaultExe)); QString app = QStandardPaths::findExecutable(defaultApp); - if (!app.isEmpty()) + if (!app.isEmpty() || !HostOsInfo::isWindowsHost()) return app; - if (HostOsInfo::isWindowsHost()) { // Windows: Use app.exe from git if it cannot be found. - FileName path = GerritPlugin::gitBinDirectory(); - if (!path.isEmpty()) - app = path.appendPath(defaultApp).toString(); - } - return app; + // Windows: Use app.exe from git if it cannot be found. + const FileName gitBinDir = GerritPlugin::gitBinDirectory(); + if (gitBinDir.isEmpty()) + return QString(); + FileName path = gitBinDir; + path.appendPath(defaultApp); + if (path.exists()) + return path.toString(); + + // If app was not found, and git bin is Git/usr/bin (Git for Windows), + // search also in Git/mingw{32,64}/bin + if (!gitBinDir.endsWith("/usr/bin")) + return QString(); + path = gitBinDir.parentDir().parentDir(); + QDir dir(path.toString()); + const QStringList entries = dir.entryList({"mingw*"}); + if (entries.isEmpty()) + return QString(); + path.appendPath(entries.first()).appendPath("bin").appendPath(defaultApp); + if (path.exists()) + return path.toString(); + return QString(); } static inline QString detectSsh()