Commit 82709dc7 authored by Tobias Hunger's avatar Tobias Hunger
Browse files

Git: Fix finding of top-level directory



Fix finding of top-level directory for git when
  * Git version >= 1.7.0 and
  * the directory queried does not exist

Task-number: QTCREATORBUG-6821
Change-Id: I54a6050b71fe924f421921b8e5b468578db1210d
Reviewed-by: default avatarAlessandro Portale <alessandro.portale@nokia.com>
parent dc73498d
......@@ -368,10 +368,24 @@ const char *GitClient::decorateOption = "--decorate";
QString GitClient::findRepositoryForDirectory(const QString &dir)
{
if (synchronousGitVersion(true) >= 0x010700) {
// Find a directory to run git in:
const QString root = QDir::rootPath();
const QString home = QDir::homePath();
QDir directory(dir);
do {
const QString absDirPath = directory.absolutePath();
if (absDirPath == root || absDirPath == home)
break;
if (directory.exists())
break;
} while (directory.cdUp());
QByteArray outputText;
QStringList arguments;
arguments << QLatin1String("rev-parse") << QLatin1String("--show-toplevel");
fullySynchronousGit(dir, arguments, &outputText, 0, false);
fullySynchronousGit(directory.absolutePath(), arguments, &outputText, 0, false);
return outputText.trimmed();
} else {
// Check for ".git/config"
......
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