Commit fdb6ef90 authored by Orgad Shaneh's avatar Orgad Shaneh Committed by Orgad Shaneh
Browse files

VCS: Do not try to add files that are already tracked



Task-number: QTCREATORBUG-2455
Change-Id: I4b1fa9676ad4a8d7293e035e4d6103251bef8aee
Reviewed-by: default avatarNikita Baryshnikov <nib952051@gmail.com>
Reviewed-by: default avatarCristian Tibirna <tibirna@kde.org>
Reviewed-by: default avatarTobias Hunger <tobias.hunger@digia.com>
parent 6f24665e
......@@ -128,6 +128,16 @@ QString BazaarClient::findTopLevelForFile(const QFileInfo &file) const
repositoryCheckFile);
}
bool BazaarClient::managesFile(const QString &workingDirectory, const QString &fileName) const
{
QStringList args(QLatin1String("status"));
args << fileName;
QByteArray stdOut;
if (!vcsFullySynchronousExec(workingDirectory, args, &stdOut))
return false;
return !stdOut.startsWith("unknown");
}
void BazaarClient::view(const QString &source, const QString &id, const QStringList &extraOptions)
{
QStringList args(QLatin1String("log"));
......
......@@ -57,6 +57,7 @@ public:
void view(const QString &source, const QString &id,
const QStringList &extraOptions = QStringList());
QString findTopLevelForFile(const QFileInfo &file) const;
bool managesFile(const QString &workingDirectory, const QString &fileName) const;
protected:
Core::Id vcsEditorKind(VcsCommand cmd) const;
......
......@@ -61,6 +61,11 @@ bool BazaarControl::managesDirectory(const QString &directory, QString *topLevel
return !topLevelFound.isEmpty();
}
bool BazaarControl::managesFile(const QString &workingDirectory, const QString &fileName) const
{
return m_bazaarClient->managesFile(workingDirectory, fileName);
}
bool BazaarControl::isConfigured() const
{
const QString binary = m_bazaarClient->settings()->binaryPath();
......
......@@ -53,6 +53,7 @@ public:
Core::Id id() const;
bool managesDirectory(const QString &filename, QString *topLevel = 0) const;
bool managesFile(const QString &workingDirectory, const QString &fileName) const;
bool isConfigured() const;
bool supportsOperation(Operation operation) const;
bool vcsOpen(const QString &fileName);
......
......@@ -134,6 +134,11 @@ bool ClearCaseControl::managesDirectory(const QString &directory, QString *topLe
return m_plugin->managesDirectory(directory, topLevel);
}
bool ClearCaseControl::managesFile(const QString &workingDirectory, const QString &fileName) const
{
return m_plugin->managesFile(workingDirectory, fileName);
}
bool ClearCaseControl::vcsAnnotate(const QString &file, int line)
{
const QFileInfo fi(file);
......
......@@ -48,6 +48,7 @@ public:
Core::Id id() const;
bool managesDirectory(const QString &directory, QString *topLevel = 0) const;
bool managesFile(const QString &workingDirectory, const QString &fileName) const;
bool isConfigured() const;
......
......@@ -1850,6 +1850,13 @@ bool ClearCasePlugin::ccCheckUcm(const QString &viewname, const QString &working
return QRegExp(QLatin1String("(^|\\n)ucm\\n")).indexIn(catcsData) != -1;
}
bool ClearCasePlugin::managesFile(const QString &workingDirectory, const QString &fileName) const
{
QStringList args;
args << QLatin1String("ls") << fileName;
return runCleartoolSync(workingDirectory, args).contains(QLatin1String("@@"));
}
ViewData ClearCasePlugin::ccGetView(const QString &workingDir) const
{
static QHash<QString, ViewData> viewCache;
......
......@@ -166,6 +166,7 @@ public:
void setStatus(const QString &file, FileStatus::Status status, bool update = true);
bool ccCheckUcm(const QString &viewname, const QString &workingDir) const;
bool managesFile(const QString &workingDirectory, const QString &fileName) const;
public slots:
void vcsAnnotate(const QString &workingDir, const QString &file,
......
......@@ -80,6 +80,14 @@ public:
virtual bool managesDirectory(const QString &filename, QString *topLevel = 0) const = 0;
/*!
* Returns whether \a fileName is managed by this version control.
*
* \a workingDirectory is assumed to be part of a valid repository (not necessarily its
* top level). \a fileName is expected to be relative to workingDirectory.
*/
virtual bool managesFile(const QString &workingDirectory, const QString &fileName) const = 0;
/*!
* Returns true is the VCS is configured to run.
*/
......
......@@ -412,11 +412,20 @@ void VcsManager::promptToAdd(const QString &directory, const QStringList &fileNa
if (!vc || !vc->supportsOperation(Core::IVersionControl::AddOperation))
return;
QStringList unmanagedFiles;
QDir dir(directory);
foreach (const QString &fileName, fileNames) {
if (!vc->managesFile(directory, dir.relativeFilePath(fileName)))
unmanagedFiles << fileName;
}
if (unmanagedFiles.isEmpty())
return;
Internal::AddToVcsDialog dlg(Core::ICore::mainWindow(), VcsManager::msgAddToVcsTitle(),
fileNames, vc->displayName());
unmanagedFiles, vc->displayName());
if (dlg.exec() == QDialog::Accepted) {
QStringList notAddedToVc;
foreach (const QString &file, fileNames) {
foreach (const QString &file, unmanagedFiles) {
if (!vc->vcsAdd(file))
notAddedToVc << file;
}
......
......@@ -163,6 +163,11 @@ bool CvsControl::managesDirectory(const QString &directory, QString *topLevel) c
return m_plugin->managesDirectory(directory, topLevel);
}
bool CvsControl::managesFile(const QString &workingDirectory, const QString &fileName) const
{
return m_plugin->managesFile(workingDirectory, fileName);
}
void CvsControl::emitRepositoryChanged(const QString &s)
{
emit repositoryChanged(s);
......
......@@ -48,6 +48,7 @@ public:
Core::Id id() const;
bool managesDirectory(const QString &directory, QString *topLevel = 0) const;
bool managesFile(const QString &workingDirectory, const QString &fileName) const;
bool isConfigured() const;
bool supportsOperation(Operation operation) const;
......
......@@ -1226,7 +1226,7 @@ CvsResponse CvsPlugin::runCvs(const QString &workingDirectory,
const QStringList &arguments,
int timeOut,
unsigned flags,
QTextCodec *outputCodec)
QTextCodec *outputCodec) const
{
const QString executable = m_settings.cvsBinaryPath;
CvsResponse response;
......@@ -1365,6 +1365,17 @@ bool CvsPlugin::managesDirectory(const QString &directory, QString *topLevel /*
return manages;
}
bool CvsPlugin::managesFile(const QString &workingDirectory, const QString &fileName) const
{
QStringList args;
args << QLatin1String("status") << fileName;
const CvsResponse response =
runCvs(workingDirectory, args, m_settings.timeOutMS(), SshPasswordPrompt);
if (response.result != CvsResponse::Ok)
return false;
return !response.stdOut.contains(QLatin1String("Status: Unknown"));
}
bool CvsPlugin::checkCVSDirectory(const QDir &directory) const
{
const QString cvsDir = directory.absoluteFilePath(QLatin1String("CVS"));
......
......@@ -90,6 +90,7 @@ public:
bool vcsAdd(const QString &workingDir, const QString &fileName);
bool vcsDelete(const QString &workingDir, const QString &fileName);
bool managesDirectory(const QString &directory, QString *topLevel = 0) const;
bool managesFile(const QString &workingDirectory, const QString &fileName) const;
// cvs 'edit' is used to implement 'open' (cvsnt).
bool edit(const QString &topLevel, const QStringList &files);
......@@ -143,7 +144,8 @@ private:
CvsResponse runCvs(const QString &workingDirectory,
const QStringList &arguments,
int timeOut,
unsigned flags, QTextCodec *outputCodec = 0);
unsigned flags,
QTextCodec *outputCodec = 0) const;
void annotate(const QString &workingDir, const QString &file,
const QString &revision = QString(), int lineNumber= -1);
......
......@@ -972,6 +972,15 @@ QString GitClient::findGitDirForRepository(const QString &repositoryDir) const
return res;
}
bool GitClient::managesFile(const QString &workingDirectory, const QString &fileName) const
{
QByteArray output;
QStringList arguments;
arguments << QLatin1String("ls-files") << QLatin1String("--error-unmatch") << fileName;
return fullySynchronousGit(workingDirectory, arguments, &output, 0,
VcsBasePlugin::SuppressCommandLogging);
}
VcsBase::VcsBaseEditorWidget *GitClient::findExistingVCSEditor(const char *registerDynamicProperty,
const QString &dynamicPropertyValue) const
{
......
......@@ -137,6 +137,7 @@ public:
QString findRepositoryForDirectory(const QString &dir);
QString findGitDirForRepository(const QString &repositoryDir) const;
bool managesFile(const QString &workingDirectory, const QString &fileName) const;
void diff(const QString &workingDirectory, const QString &fileName);
void diff(const QString &workingDirectory,
......
......@@ -229,6 +229,11 @@ bool GitVersionControl::managesDirectory(const QString &directory, QString *topL
return !topLevelFound.isEmpty();
}
bool GitVersionControl::managesFile(const QString &workingDirectory, const QString &fileName) const
{
return m_client->managesFile(workingDirectory, fileName);
}
bool GitVersionControl::vcsAnnotate(const QString &file, int line)
{
const QFileInfo fi(file);
......
......@@ -48,6 +48,7 @@ public:
Core::Id id() const;
bool managesDirectory(const QString &directory, QString *topLevel) const;
bool managesFile(const QString &workingDirectory, const QString &fileName) const;
bool isConfigured() const;
bool supportsOperation(Operation operation) const;
......
......@@ -257,6 +257,15 @@ QString MercurialClient::vcsGetRepositoryURL(const QString &directory)
return QString();
}
bool MercurialClient::managesFile(const QString &workingDirectory, const QString &fileName) const
{
QStringList args;
args << QLatin1String("status") << QLatin1String("--unknown") << fileName;
QByteArray output;
vcsFullySynchronousExec(workingDirectory, args, &output);
return output.isEmpty();
}
void MercurialClient::incoming(const QString &repositoryRoot, const QString &repository)
{
QStringList args;
......
......@@ -63,6 +63,7 @@ public:
void incoming(const QString &repositoryRoot, const QString &repository = QString());
void outgoing(const QString &repositoryRoot);
QString vcsGetRepositoryURL(const QString &directory);
bool managesFile(const QString &workingDirectory, const QString &fileName) const;
void annotate(const QString &workingDir, const QString &file,
const QString revision = QString(), int lineNumber = -1,
......
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