forked from qt-creator/qt-creator
VCS[git]: Add support for cleaning a repository.
Present user with a checkable list of files to be cleaned (add reusable dialog to VCSBase module).
This commit is contained in:
@@ -949,6 +949,30 @@ bool GitClient::synchronousShow(const QString &workingDirectory, const QString &
|
||||
return true;
|
||||
}
|
||||
|
||||
// Retrieve list of files to be cleaned
|
||||
bool GitClient::synchronousCleanList(const QString &workingDirectory,
|
||||
QStringList *files, QString *errorMessage)
|
||||
{
|
||||
if (Git::Constants::debug)
|
||||
qDebug() << Q_FUNC_INFO << workingDirectory;
|
||||
files->clear();
|
||||
QStringList args;
|
||||
args << QLatin1String("clean") << QLatin1String("--dry-run") << QLatin1String("-dxf");
|
||||
QByteArray outputText;
|
||||
QByteArray errorText;
|
||||
const bool rc = synchronousGit(workingDirectory, args, &outputText, &errorText);
|
||||
if (!rc) {
|
||||
*errorMessage = tr("Unable to run clean --dry-run: %1: %2").arg(workingDirectory, commandOutputFromLocal8Bit(errorText));
|
||||
return false;
|
||||
}
|
||||
// Filter files that git would remove
|
||||
const QString prefix = QLatin1String("Would remove ");
|
||||
foreach(const QString &line, commandOutputLinesFromLocal8Bit(outputText))
|
||||
if (line.startsWith(prefix))
|
||||
files->push_back(line.mid(prefix.size()));
|
||||
return true;
|
||||
}
|
||||
|
||||
// Factory function to create an asynchronous command
|
||||
GitCommand *GitClient::createCommand(const QString &workingDirectory,
|
||||
VCSBase::VCSBaseEditor* editor,
|
||||
|
||||
@@ -105,6 +105,7 @@ public:
|
||||
bool synchronousReset(const QString &workingDirectory,
|
||||
const QStringList &files = QStringList(),
|
||||
QString *errorMessage = 0);
|
||||
bool synchronousCleanList(const QString &workingDirectory, QStringList *files, QString *errorMessage);
|
||||
bool synchronousInit(const QString &workingDirectory);
|
||||
bool synchronousCheckoutFiles(const QString &workingDirectory,
|
||||
QStringList files = QStringList(),
|
||||
|
||||
@@ -56,6 +56,7 @@
|
||||
#include <vcsbase/vcsbaseeditor.h>
|
||||
#include <vcsbase/basevcssubmiteditorfactory.h>
|
||||
#include <vcsbase/vcsbaseoutputwindow.h>
|
||||
#include <vcsbase/cleandialog.h>
|
||||
#include <locator/commandlocator.h>
|
||||
|
||||
#include <QtCore/QDebug>
|
||||
@@ -132,6 +133,7 @@ GitPlugin::GitPlugin() :
|
||||
m_commitAction(0),
|
||||
m_pullAction(0),
|
||||
m_pushAction(0),
|
||||
m_cleanAction(0),
|
||||
m_submitCurrentAction(0),
|
||||
m_diffSelectedFilesAction(0),
|
||||
m_undoAction(0),
|
||||
@@ -332,6 +334,12 @@ bool GitPlugin::initialize(const QStringList &arguments, QString *errorMessage)
|
||||
connect(m_createRepositoryAction, SIGNAL(triggered()), this, SLOT(createRepository()));
|
||||
gitContainer->addAction(command);
|
||||
|
||||
m_cleanAction = new QAction(tr("Clean Repository..."), this);
|
||||
command = actionManager->registerAction(m_cleanAction, "Git.CleanRepository", globalcontext);
|
||||
connect(m_cleanAction, SIGNAL(triggered()), this, SLOT(cleanRepository()));
|
||||
gitContainer->addAction(command);
|
||||
m_commandLocator->appendCommand(command);
|
||||
|
||||
gitContainer->addAction(createSeparator(actionManager, globalcontext, QLatin1String("Git.Sep.Global"), this));
|
||||
|
||||
m_stashSnapshotAction = new QAction(tr("Stash snapshot..."), this);
|
||||
@@ -680,6 +688,42 @@ void GitPlugin::push()
|
||||
m_gitClient->push(state.topLevel());
|
||||
}
|
||||
|
||||
void GitPlugin::cleanRepository()
|
||||
{
|
||||
const VCSBase::VCSBasePluginState state = currentState();
|
||||
QTC_ASSERT(state.hasTopLevel(), return);
|
||||
|
||||
// Find files to be deleted
|
||||
QString errorMessage;
|
||||
QStringList files;
|
||||
QApplication::setOverrideCursor(Qt::WaitCursor);
|
||||
const bool gotFiles = m_gitClient->synchronousCleanList(state.topLevel(), &files, &errorMessage);
|
||||
QApplication::restoreOverrideCursor();
|
||||
|
||||
QWidget *parent = Core::ICore::instance()->mainWindow();
|
||||
if (!gotFiles) {
|
||||
QMessageBox::warning(parent, tr("Unable to retrieve file list"),
|
||||
errorMessage);
|
||||
return;
|
||||
}
|
||||
if (files.isEmpty()) {
|
||||
QMessageBox::information(parent, tr("Repository clean"),
|
||||
tr("The repository is clean."));
|
||||
return;
|
||||
}
|
||||
// Clean the trailing slash of directories
|
||||
const QChar slash = QLatin1Char('/');
|
||||
const QStringList::iterator end = files.end();
|
||||
for (QStringList::iterator it = files.begin(); it != end; ++it)
|
||||
if (it->endsWith(slash))
|
||||
it->truncate(it->size() - 1);
|
||||
|
||||
// Show in dialog
|
||||
VCSBase::CleanDialog dialog(parent);
|
||||
dialog.setFileList(state.topLevel(), files);
|
||||
dialog.exec();
|
||||
}
|
||||
|
||||
void GitPlugin::stash()
|
||||
{
|
||||
// Simple stash without prompt, reset repo.
|
||||
@@ -780,6 +824,7 @@ void GitPlugin::updateActions(VCSBase::VCSBasePlugin::ActionState as)
|
||||
m_logRepositoryAction->setEnabled(repositoryEnabled);
|
||||
m_undoRepositoryAction->setEnabled(repositoryEnabled);
|
||||
m_pushAction->setEnabled(repositoryEnabled);
|
||||
m_cleanAction->setEnabled(repositoryEnabled);
|
||||
|
||||
// Prompts for repo.
|
||||
m_showAction->setEnabled(true);
|
||||
|
||||
@@ -105,6 +105,7 @@ private slots:
|
||||
void undoRepositoryChanges();
|
||||
void stageFile();
|
||||
void unstageFile();
|
||||
void cleanRepository();
|
||||
|
||||
void showCommit();
|
||||
void startCommit();
|
||||
@@ -146,6 +147,7 @@ private:
|
||||
QAction *m_commitAction;
|
||||
QAction *m_pullAction;
|
||||
QAction *m_pushAction;
|
||||
QAction *m_cleanAction;
|
||||
|
||||
QAction *m_submitCurrentAction;
|
||||
QAction *m_diffSelectedFilesAction;
|
||||
|
||||
Reference in New Issue
Block a user