Commit 623fe183 authored by Aleix Pol Gonzalez's avatar Aleix Pol Gonzalez 🐧
Browse files

Fix .git directory look-up when calling dotGitDirectory on the repo root

Porting bug, includes unit test for patches, which is how I found the
problem
parent 33f52f97
......@@ -82,11 +82,15 @@ namespace
QDir dotGitDirectory(const QUrl& dirPath)
{
const QFileInfo finfo(dirPath.toLocalFile());
QDir dir = finfo.absoluteDir();
QDir dir = finfo.isDir() ? QDir(finfo.filePath()): finfo.absoluteDir();
static const QString gitDir(".git");
static const QString gitDir = QStringLiteral(".git");
while (!dir.exists(gitDir) && dir.cdUp()) {} // cdUp, until there is a sub-directory called .git
if (dir.isRoot()) {
qWarning() << "couldn't find the git root for" << dirPath;
}
return dir;
}
......
......@@ -420,6 +420,25 @@ void GitInitTest::removeTempDirs()
}
}
void GitInitTest::testDiff()
{
repoInit();
addFiles();
commitFiles();
QVERIFY(writeFile(gitTest_BaseDir + gitTest_FileName, "something else"));
VcsRevision srcrev = VcsRevision::createSpecialRevision(VcsRevision::Base);
VcsRevision dstrev = VcsRevision::createSpecialRevision(VcsRevision::Working);
VcsJob* j = m_plugin->diff(QUrl::fromLocalFile(gitTest_BaseDir), srcrev, dstrev, VcsDiff::DiffUnified, IBasicVersionControl::Recursive);
VERIFYJOB(j);
KDevelop::VcsDiff d = j->fetchResults().value<KDevelop::VcsDiff>();
QVERIFY(d.baseDiff().isLocalFile());
QString path = d.baseDiff().toLocalFile();
QVERIFY(QDir().exists(path+"/.git"));
}
QTEST_MAIN(GitInitTest)
// #include "gittest.moc"
......@@ -61,6 +61,7 @@ private slots:
void testRemoveEmptyFolderInFolder();
void testRemoveUnindexedFile();
void testRemoveFolderContainingUnversionedFiles();
void testDiff();
private:
GitPlugin* m_plugin;
......
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