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: Alessandro Portale <alessandro.portale@nokia.com>
This commit is contained in:
Tobias Hunger
2012-01-17 11:02:56 +01:00
parent dc73498d34
commit 82709dc766

View File

@@ -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"