Commit d5271a08 authored by Friedemann Kleint's avatar Friedemann Kleint
Browse files

VCS[hg, git]: Add support for repository creation.

Add repository creation operation to IVersionControl, implement for hg
and git, add convenience slot with prompts to VCSBasePlugin.
Add respective menu options and make menus are visible in case no VCS is
active.
Change project wizards extension page to list VCS that are capable of
repository creation in a QComboBox in case the directory is not managed
by another VCS (in which case it lists that one for operation 'add').
On that occasion, polish the Project selection to use a QComboBox as
well and add some smartness to find the most suitable project to add via
path matching.
parent 5ab250fe
......@@ -41,9 +41,10 @@ class CORE_EXPORT IVersionControl : public QObject
{
Q_OBJECT
public:
enum Operation { AddOperation, DeleteOperation, OpenOperation };
enum Operation { AddOperation, DeleteOperation, OpenOperation,
CreateRepositoryOperation };
IVersionControl(QObject *parent = 0) : QObject(parent) {}
explicit IVersionControl(QObject *parent = 0) : QObject(parent) {}
virtual ~IVersionControl() {}
virtual QString displayName() const = 0;
......@@ -93,12 +94,14 @@ public:
/*!
* Called after a file has been removed from the project (if the user
* wants), e.g. 'p4 delete', 'svn delete'.
*
* You probably want to call VcsManager::showDeleteDialog, which asks the
* user to confirm the deletion.
*/
virtual bool vcsDelete(const QString &filename) = 0;
/*!
* Called to initialize the version control systemin a directory.
*/
virtual bool vcsCreateRepository(const QString &directory) = 0;
signals:
void repositoryChanged(const QString &repository);
void filesChanged(const QStringList &files);
......
......@@ -54,6 +54,7 @@ bool CVSControl::supportsOperation(Operation operation) const
case DeleteOperation:
break;
case OpenOperation:
case CreateRepositoryOperation:
rc = false;
break;
}
......@@ -78,6 +79,11 @@ bool CVSControl::vcsDelete(const QString &fileName)
return m_plugin->vcsDelete(fi.absolutePath(), fi.fileName());
}
bool CVSControl::vcsCreateRepository(const QString &)
{
return false;
}
bool CVSControl::managesDirectory(const QString &directory) const
{
return m_plugin->managesDirectory(directory);
......
......@@ -52,6 +52,7 @@ public:
virtual bool vcsOpen(const QString &fileName);
virtual bool vcsAdd(const QString &fileName);
virtual bool vcsDelete(const QString &filename);
virtual bool vcsCreateRepository(const QString &directory);
void emitRepositoryChanged(const QString &s);
void emitFilesChanged(const QStringList &l);
......
......@@ -498,7 +498,7 @@ CVSSubmitEditor *CVSPlugin::openCVSSubmitEditor(const QString &fileName)
void CVSPlugin::updateActions(VCSBase::VCSBasePlugin::ActionState as)
{
if (!VCSBase::VCSBasePlugin::enableMenuAction(as, m_menuAction))
if (!enableMenuAction(as, m_menuAction))
return;
m_logRepositoryAction->setEnabled(currentState().hasTopLevel());
......
......@@ -446,6 +446,22 @@ bool GitClient::synchronousReset(const QString &workingDirectory,
return true;
}
// Initialize repository
bool GitClient::synchronousInit(const QString &workingDirectory)
{
if (Git::Constants::debug)
qDebug() << Q_FUNC_INFO << workingDirectory;
QByteArray outputText;
QByteArray errorText;
const QStringList arguments(QLatin1String("init"));
const bool rc = synchronousGit(workingDirectory, arguments, &outputText, &errorText);
// '[Re]Initialized...'
VCSBase::VCSBaseOutputWindow::instance()->append(QString::fromLocal8Bit(outputText));
if (!rc)
VCSBase::VCSBaseOutputWindow::instance()->append(QString::fromLocal8Bit(errorText));
return rc;
}
bool GitClient::synchronousCheckout(const QString &workingDirectory,
const QStringList &files,
QString *errorMessage)
......
......@@ -92,6 +92,7 @@ public:
bool synchronousAdd(const QString &workingDirectory, const QStringList &files);
bool synchronousReset(const QString &workingDirectory, const QStringList &files);
bool synchronousReset(const QString &workingDirectory, const QStringList &files, QString *errorMessage);
bool synchronousInit(const QString &workingDirectory);
bool synchronousCheckout(const QString &workingDirectory, const QStringList &files, QString *errorMessage);
bool synchronousStash(const QString &workingDirectory, QString *errorMessage);
bool synchronousBranchCmd(const QString &workingDirectory, QStringList branchArgs,
......
......@@ -122,6 +122,7 @@ GitPlugin::GitPlugin() :
m_undoFileAction(0),
m_logRepositoryAction(0),
m_undoRepositoryAction(0),
m_createRepositoryAction(0),
m_showAction(0),
m_stageAction(0),
m_unstageAction(0),
......@@ -306,6 +307,11 @@ bool GitPlugin::initialize(const QStringList &arguments, QString *errorMessage)
connect(m_undoRepositoryAction, SIGNAL(triggered()), this, SLOT(undoRepositoryChanges()));
gitContainer->addAction(command);
m_createRepositoryAction = new QAction(tr("Create Repository..."), this);
command = actionManager->registerAction(m_createRepositoryAction, "Git.CreateRepository", globalcontext);
connect(m_createRepositoryAction, SIGNAL(triggered()), this, SLOT(createRepository()));
gitContainer->addAction(command);
gitContainer->addAction(createSeparator(actionManager, globalcontext, QLatin1String("Git.Sep.Global"), this));
m_stashAction = new QAction(tr("Stash"), this);
......@@ -677,9 +683,10 @@ void GitPlugin::stashList()
void GitPlugin::updateActions(VCSBase::VCSBasePlugin::ActionState as)
{
if (!VCSBase::VCSBasePlugin::enableMenuAction(as, m_menuAction))
if (!enableMenuAction(as, m_menuAction))
return;
// Note: This menu is visible if there is no repository. Only
// 'Create Repository'/'Show' actions should be available.
const QString fileName = currentState().currentFileName();
m_diffAction->setParameter(fileName);
m_logAction->setParameter(fileName);
......@@ -708,9 +715,13 @@ void GitPlugin::updateActions(VCSBase::VCSBasePlugin::ActionState as)
m_statusRepositoryAction->setEnabled(repositoryEnabled);
m_branchListAction->setEnabled(repositoryEnabled);
m_stashListAction->setEnabled(repositoryEnabled);
m_stashAction->setEnabled(repositoryEnabled);
m_pullAction->setEnabled(repositoryEnabled);
m_commitAction->setEnabled(repositoryEnabled);
m_stashPopAction->setEnabled(repositoryEnabled);
m_logRepositoryAction->setEnabled(repositoryEnabled);
m_undoRepositoryAction->setEnabled(repositoryEnabled);
m_pushAction->setEnabled(repositoryEnabled);
// Prompts for repo.
m_showAction->setEnabled(true);
......
......@@ -131,6 +131,7 @@ private:
Utils::ParameterAction *m_undoFileAction;
QAction *m_logRepositoryAction;
QAction *m_undoRepositoryAction;
QAction *m_createRepositoryAction;
QAction *m_showAction;
Utils::ParameterAction *m_stageAction;
......
......@@ -29,6 +29,7 @@
#include "gitversioncontrol.h"
#include "gitclient.h"
#include "gitplugin.h"
namespace Git {
namespace Internal {
......@@ -52,6 +53,9 @@ bool GitVersionControl::supportsOperation(Operation operation) const
case DeleteOperation:
case OpenOperation:
break;
case CreateRepositoryOperation:
rc = true;
break;
}
return rc;
}
......@@ -72,10 +76,14 @@ bool GitVersionControl::vcsDelete(const QString & /*fileName*/)
return false;
}
bool GitVersionControl::vcsCreateRepository(const QString &directory)
{
return GitPlugin::instance()->gitClient()->synchronousInit(directory);
}
bool GitVersionControl::managesDirectory(const QString &directory) const
{
return !GitClient::findRepositoryForDirectory(directory).isEmpty();
}
QString GitVersionControl::findTopLevelForDirectory(const QString &directory) const
......
......@@ -53,6 +53,7 @@ public:
virtual bool vcsOpen(const QString &fileName);
virtual bool vcsAdd(const QString &fileName);
virtual bool vcsDelete(const QString &filename);
virtual bool vcsCreateRepository(const QString &directory);
void emitFilesChanged(const QStringList &);
......
......@@ -107,6 +107,7 @@ const char * const IMPORT = "Mercurial.Action.Import";
const char * const INCOMING = "Mercurial.Action.Incoming";
const char * const OUTGOING = "Mercurial.Action.Outgoing";
const char * const COMMIT = "Mercurial.Action.Commit";
const char * const CREATE_REPOSITORY = "Mercurial.Action.CreateRepository";
//Repository Management
const char * const MERGE = "Mercurial.Action.Merge";
......
......@@ -366,6 +366,18 @@ void MercurialClient::revert(const QString &workingDir,
enqueueJob(job);
}
bool MercurialClient::createRepositorySync(const QString &workingDirectory)
{
const QStringList args(QLatin1String("init"));
QByteArray outputData;
if (!executeHgSynchronously(workingDirectory, args, &outputData))
return false;
QString output = QString::fromLocal8Bit(outputData);
output.remove(QLatin1Char('\r'));
VCSBase::VCSBaseOutputWindow::instance()->append(output);
return true;
}
void MercurialClient::status(const QString &workingDir, const QString &file)
{
QStringList args(QLatin1String("status"));
......
......@@ -88,6 +88,7 @@ public:
void statusWithSignal(const QString &repository);
void revertFile(const QString &workingDir, const QString &file, const QString &revision = QString());
void revertRepository(const QString &workingDir, const QString &revision = QString());
bool createRepositorySync(const QString &workingDir);
void update(const QString &repositoryRoot, const QString &revision = QString());
void commit(const QString &repositoryRoot,
const QStringList &files,
......
......@@ -62,17 +62,15 @@ QString MercurialControl::findTopLevelForDirectory(const QString &directory) con
bool MercurialControl::supportsOperation(Operation operation) const
{
bool supported = true;
switch (operation) {
case Core::IVersionControl::AddOperation:
case Core::IVersionControl::DeleteOperation:
case Core::IVersionControl::CreateRepositoryOperation:
break;
case Core::IVersionControl::OpenOperation:
default:
supported = false;
break;
}
return supported;
}
......@@ -94,6 +92,11 @@ bool MercurialControl::vcsDelete(const QString &filename)
return mercurialClient->remove(fi.absolutePath(), fi.fileName());
}
bool MercurialControl::vcsCreateRepository(const QString &directory)
{
return mercurialClient->createRepositorySync(directory);
}
bool MercurialControl::sccManaged(const QString &filename)
{
const QFileInfo fi(filename);
......
......@@ -56,6 +56,7 @@ public:
bool vcsOpen(const QString &fileName);
bool vcsAdd(const QString &filename);
bool vcsDelete(const QString &filename);
bool vcsCreateRepository(const QString &directory);
bool sccManaged(const QString &filename);
public slots:
......
......@@ -127,6 +127,7 @@ MercurialPlugin::MercurialPlugin() :
changeLog(0),
m_addAction(0),
m_deleteAction(0),
m_createRepositoryAction(0),
m_menuAction(0)
{
m_instance = this;
......@@ -429,6 +430,11 @@ void MercurialPlugin::createRepositoryActions(const QList<int> &context)
command->setDefaultKeySequence(QKeySequence(tr("Alt+H,Alt+C")));
connect(action, SIGNAL(triggered()), this, SLOT(commit()));
mercurialContainer->addAction(command);
m_createRepositoryAction = new QAction(tr("Create Repository..."), this);
command = actionManager->registerAction(m_createRepositoryAction, QLatin1String(Constants::CREATE_REPOSITORY), context);
connect(m_createRepositoryAction, SIGNAL(triggered()), this, SLOT(createRepository()));
mercurialContainer->addAction(command);
}
void MercurialPlugin::pull()
......@@ -675,7 +681,7 @@ void MercurialPlugin::createSeparator(const QList<int> &context, const QString &
void MercurialPlugin::updateActions(VCSBase::VCSBasePlugin::ActionState as)
{
if (!VCSBase::VCSBasePlugin::enableMenuAction(as, m_menuAction))
if (!enableMenuAction(as, m_menuAction))
return;
const QString filename = currentState().currentFileName();
......
......@@ -166,6 +166,7 @@ private:
Utils::ParameterAction *revertFile;
Utils::ParameterAction *statusFile;
QAction *m_createRepositoryAction;
//submit editor actions
QAction *editorCommit;
QAction *editorDiff;
......
......@@ -788,7 +788,7 @@ void PerforcePlugin::filelog(const QString &workingDir, const QStringList &fileN
void PerforcePlugin::updateActions(VCSBase::VCSBasePlugin::ActionState as)
{
if (!VCSBase::VCSBasePlugin::enableMenuAction(as, m_menuAction))
if (!enableMenuAction(as, m_menuAction))
return;
m_logRepositoryAction->setEnabled(currentState().hasTopLevel());
......
......@@ -50,14 +50,15 @@ QString PerforceVersionControl::displayName() const
bool PerforceVersionControl::supportsOperation(Operation operation) const
{
bool rc = true;
switch (operation) {
case AddOperation:
case DeleteOperation:
case OpenOperation:
return true;
case CreateRepositoryOperation:
break;
}
return rc;
return false;
}
bool PerforceVersionControl::vcsOpen(const QString &fileName)
......@@ -78,6 +79,11 @@ bool PerforceVersionControl::vcsDelete(const QString &fileName)
return m_plugin->vcsDelete(fi.absolutePath(), fi.fileName());
}
bool PerforceVersionControl::vcsCreateRepository(const QString &)
{
return false;
}
bool PerforceVersionControl::managesDirectory(const QString &directory) const
{
const bool rc = m_plugin->managesDirectory(directory);
......
......@@ -52,6 +52,7 @@ public:
virtual bool vcsOpen(const QString &fileName);
virtual bool vcsAdd(const QString &fileName);
virtual bool vcsDelete(const QString &filename);
virtual bool vcsCreateRepository(const QString &directory);
void emitRepositoryChanged(const QString &s);
void emitFilesChanged(const QStringList &l);
......
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