forked from qt-creator/qt-creator
VCS[git/hg]: Prevent search for repository from creating folders
... when autofs is involved. Check for files instead of folders and stop checking/recursing up at '/' or $HOME. Further fixup will follow. Task-number: QTCREATORBUG-1361 Task-number: QTBUG-10495
This commit is contained in:
@@ -52,6 +52,7 @@
|
|||||||
#include <utils/synchronousprocess.h>
|
#include <utils/synchronousprocess.h>
|
||||||
#include <vcsbase/vcsbaseeditor.h>
|
#include <vcsbase/vcsbaseeditor.h>
|
||||||
#include <vcsbase/vcsbaseoutputwindow.h>
|
#include <vcsbase/vcsbaseoutputwindow.h>
|
||||||
|
#include <vcsbase/vcsbaseplugin.h>
|
||||||
|
|
||||||
#include <projectexplorer/environment.h>
|
#include <projectexplorer/environment.h>
|
||||||
|
|
||||||
@@ -155,13 +156,9 @@ const char *GitClient::noColorOption = "--no-color";
|
|||||||
|
|
||||||
QString GitClient::findRepositoryForDirectory(const QString &dir)
|
QString GitClient::findRepositoryForDirectory(const QString &dir)
|
||||||
{
|
{
|
||||||
const QString gitDirectory = QLatin1String(kGitDirectoryC);
|
// Check for ".git/config"
|
||||||
QDir directory(dir);
|
const QString checkFile = QLatin1String(kGitDirectoryC) + QLatin1String("/config");
|
||||||
do {
|
return VCSBase::VCSBasePlugin::findRepositoryForDirectory(dir, checkFile);
|
||||||
if (QFileInfo(directory, gitDirectory).isDir())
|
|
||||||
return directory.absolutePath();
|
|
||||||
} while (directory.cdUp());
|
|
||||||
return QString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Create an editor associated to VCS output of a source file/directory
|
/* Create an editor associated to VCS output of a source file/directory
|
||||||
|
|||||||
@@ -72,9 +72,6 @@ public:
|
|||||||
explicit GitClient(GitPlugin *plugin);
|
explicit GitClient(GitPlugin *plugin);
|
||||||
~GitClient();
|
~GitClient();
|
||||||
|
|
||||||
bool managesDirectory(const QString &) const { return false; }
|
|
||||||
QString findTopLevelForDirectory(const QString &) const { return QString(); }
|
|
||||||
|
|
||||||
static QString findRepositoryForDirectory(const QString &dir);
|
static QString findRepositoryForDirectory(const QString &dir);
|
||||||
|
|
||||||
void diff(const QString &workingDirectory, const QStringList &diffArgs, const QString &fileName);
|
void diff(const QString &workingDirectory, const QStringList &diffArgs, const QString &fileName);
|
||||||
|
|||||||
@@ -548,15 +548,10 @@ void MercurialClient::commit(const QString &repositoryRoot, const QStringList &f
|
|||||||
|
|
||||||
QString MercurialClient::findTopLevelForFile(const QFileInfo &file)
|
QString MercurialClient::findTopLevelForFile(const QFileInfo &file)
|
||||||
{
|
{
|
||||||
const QString repositoryTopDir = QLatin1String(Constants::MECURIALREPO);
|
const QString repositoryCheckFile = QLatin1String(Constants::MECURIALREPO) + QLatin1String("/requires");
|
||||||
QDir dir = file.isDir() ? QDir(file.absoluteFilePath()) : QDir(file.absolutePath());
|
return file.isDir() ?
|
||||||
|
VCSBase::VCSBasePlugin::findRepositoryForDirectory(file.absoluteFilePath(), repositoryCheckFile) :
|
||||||
do {
|
VCSBase::VCSBasePlugin::findRepositoryForDirectory(file.absolutePath(), repositoryCheckFile);
|
||||||
if (QFileInfo(dir, repositoryTopDir).exists())
|
|
||||||
return dir.absolutePath();
|
|
||||||
} while (dir.cdUp());
|
|
||||||
|
|
||||||
return QString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MercurialClient::settingsChanged()
|
void MercurialClient::settingsChanged()
|
||||||
|
|||||||
@@ -54,7 +54,7 @@
|
|||||||
#include <QtGui/QFileDialog>
|
#include <QtGui/QFileDialog>
|
||||||
#include <QtGui/QMainWindow>
|
#include <QtGui/QMainWindow>
|
||||||
|
|
||||||
enum { debug = 0 };
|
enum { debug = 0, debugRepositorySearch = 0 };
|
||||||
|
|
||||||
namespace VCSBase {
|
namespace VCSBase {
|
||||||
|
|
||||||
@@ -636,6 +636,40 @@ void VCSBasePlugin::slotTestRemoveSnapshot()
|
|||||||
d->m_testLastSnapshot.clear();
|
d->m_testLastSnapshot.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Find top level for version controls like git/Mercurial that have
|
||||||
|
// a directory at the top of the repository.
|
||||||
|
// Note that checking for the existence of files is preferred over directories
|
||||||
|
// since checking for directories can cause them to be created when
|
||||||
|
// AutoFS is used (due its automatically creating mountpoints when querying
|
||||||
|
// a directory). In addition, bail out when reaching the home directory
|
||||||
|
// of the user or root (generally avoid '/', where mountpoints are created).
|
||||||
|
QString VCSBasePlugin::findRepositoryForDirectory(const QString &dirS,
|
||||||
|
const QString &checkFile)
|
||||||
|
{
|
||||||
|
if (debugRepositorySearch)
|
||||||
|
qDebug() << ">VCSBasePlugin::findRepositoryForDirectory" << dirS << checkFile;
|
||||||
|
QTC_ASSERT(!dirS.isEmpty() && !checkFile.isEmpty(), return QString());
|
||||||
|
|
||||||
|
const QString root = QDir::rootPath();
|
||||||
|
const QString home = QDir::homePath();
|
||||||
|
|
||||||
|
QDir directory(dirS);
|
||||||
|
do {
|
||||||
|
const QString absDirPath = directory.absolutePath();
|
||||||
|
if (absDirPath == root || absDirPath == home)
|
||||||
|
break;
|
||||||
|
|
||||||
|
if (QFileInfo(directory, checkFile).isFile()) {
|
||||||
|
if (debugRepositorySearch)
|
||||||
|
qDebug() << "<VCSBasePlugin::findRepositoryForDirectory> " << absDirPath;
|
||||||
|
return absDirPath;
|
||||||
|
}
|
||||||
|
} while (directory.cdUp());
|
||||||
|
if (debugRepositorySearch)
|
||||||
|
qDebug() << "<VCSBasePlugin::findRepositoryForDirectory bailing out at " << directory.absolutePath();
|
||||||
|
return QString();
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace VCSBase
|
} // namespace VCSBase
|
||||||
|
|
||||||
#include "vcsbaseplugin.moc"
|
#include "vcsbaseplugin.moc"
|
||||||
|
|||||||
@@ -163,6 +163,12 @@ public:
|
|||||||
// For internal tests: Create actions driving IVersionControl's snapshot interface.
|
// For internal tests: Create actions driving IVersionControl's snapshot interface.
|
||||||
QList<QAction*> createSnapShotTestActions();
|
QList<QAction*> createSnapShotTestActions();
|
||||||
|
|
||||||
|
// Convenience that searches for the repository specifically for version control
|
||||||
|
// systems that do not have directories like "CVS" in each managed subdirectory
|
||||||
|
// but have a directory at the top of the repository like ".git" containing
|
||||||
|
// a well known file. See implementation for gory details.
|
||||||
|
static QString findRepositoryForDirectory(const QString &dir, const QString &checkFile);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
// Convenience slot for "Delete current file" action. Prompts to
|
// Convenience slot for "Delete current file" action. Prompts to
|
||||||
// delete the file via VCSManager.
|
// delete the file via VCSManager.
|
||||||
|
|||||||
Reference in New Issue
Block a user