Git: Replace CloneWizard with a Json wizard

Change-Id: I2188c083665acc239bc98bf857ff57b071805fbc
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
This commit is contained in:
Tobias Hunger
2015-05-12 16:12:48 +02:00
parent bf249dc660
commit 3d0b690d31
20 changed files with 124 additions and 1376 deletions

View File

@@ -1,85 +0,0 @@
/****************************************************************************
**
** Copyright (C) 2015 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms and
** conditions see http://www.qt.io/terms-conditions. For further information
** use the contact form at http://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, The Qt Company gives you certain additional
** rights. These rights are described in The Qt Company LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
#include "clonewizard.h"
#include "clonewizardpage.h"
#include "gitplugin.h"
#include "gitversioncontrol.h"
#include <vcsbase/vcsbaseconstants.h>
#include <vcsbase/wizard/vcsconfigurationpage.h>
#include <utils/qtcassert.h>
using namespace VcsBase;
namespace Git {
namespace Internal {
// --------------------------------------------------------------------
// CloneWizard:
// --------------------------------------------------------------------
CloneWizard::CloneWizard(const Utils::FileName &path, QWidget *parent) :
BaseCheckoutWizard(Constants::VCS_ID_GIT, parent)
{
setTitle(tr("Cloning"));
setStartedStatus(tr("Cloning started..."));
auto cwp = new CloneWizardPage;
cwp->setPath(path.toString());
addPage(cwp);
}
VcsCommand *CloneWizard::createCommand(Utils::FileName *checkoutDir)
{
// Collect parameters for the clone command.
const CloneWizardPage *cwp = find<CloneWizardPage>();
QTC_ASSERT(cwp, return 0);
const QString baseDirectory = cwp->path();
const QString subDirectory = cwp->directory();
*checkoutDir = Utils::FileName::fromString(baseDirectory + QLatin1Char('/') + subDirectory);
const QString checkoutBranch = cwp->branch();
QStringList args;
if (!checkoutBranch.isEmpty())
args << QLatin1String("--branch") << checkoutBranch;
if (cwp->isRecursive())
args << QLatin1String("--recursive");
return createCommandImpl(cwp->repository(), Utils::FileName::fromString(baseDirectory),
subDirectory, args);
}
} // namespace Internal
} // namespace Git

View File

@@ -1,54 +0,0 @@
/****************************************************************************
**
** Copyright (C) 2015 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms and
** conditions see http://www.qt.io/terms-conditions. For further information
** use the contact form at http://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, The Qt Company gives you certain additional
** rights. These rights are described in The Qt Company LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
#ifndef CLONEWIZARD_H
#define CLONEWIZARD_H
#include <vcsbase/basecheckoutwizardfactory.h>
#include <vcsbase/basecheckoutwizard.h>
namespace Git {
namespace Internal {
class CloneWizard : public VcsBase::BaseCheckoutWizard
{
Q_OBJECT
public:
CloneWizard(const Utils::FileName &path, QWidget *parent = 0);
protected:
VcsBase::VcsCommand *createCommand(Utils::FileName *checkoutDir) override;
};
} // namespace Internal
} // namespace Git
#endif // CLONEWIZARD_H

View File

@@ -1,141 +0,0 @@
/****************************************************************************
**
** Copyright (C) 2015 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms and
** conditions see http://www.qt.io/terms-conditions. For further information
** use the contact form at http://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, The Qt Company gives you certain additional
** rights. These rights are described in The Qt Company LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
#include "clonewizardpage.h"
#include "gitplugin.h"
#include "gitclient.h"
#include <vcsbase/vcscommand.h>
#include <QCheckBox>
using namespace VcsBase;
namespace Git {
struct CloneWizardPagePrivate
{
CloneWizardPagePrivate();
bool urlIsLocal(const QString &url);
const QString mainLinePostfix;
const QString gitPostFix;
QCheckBox *recursiveCheckBox;
};
CloneWizardPagePrivate::CloneWizardPagePrivate() :
mainLinePostfix(QLatin1String("/mainline.git")),
gitPostFix(QLatin1String(".git")),
recursiveCheckBox(0)
{
}
bool CloneWizardPagePrivate::urlIsLocal(const QString &url)
{
if (url.startsWith(QLatin1String("file://"))
|| url.startsWith(QLatin1Char('/'))
|| (url.at(0).isLetter() && url.at(1) == QLatin1Char(':') && url.at(2) == QLatin1Char('\\')))
return true;
return false;
}
CloneWizardPage::CloneWizardPage(QWidget *parent) :
BaseCheckoutWizardPage(parent),
d(new CloneWizardPagePrivate)
{
setTitle(tr("Location"));
setSubTitle(tr("Specify repository URL, checkout directory and path."));
setRepositoryLabel(tr("Clone URL:"));
d->recursiveCheckBox = new QCheckBox(tr("Recursive"));
addLocalControl(d->recursiveCheckBox);
}
CloneWizardPage::~CloneWizardPage()
{
delete d;
}
QString CloneWizardPage::directoryFromRepository(const QString &urlIn) const
{
const QChar slash = QLatin1Char('/');
QString url = urlIn.trimmed().replace(QLatin1Char('\\'), slash);
// Remove postfixes
if (url.endsWith(d->mainLinePostfix))
url.truncate(url.size() - d->mainLinePostfix.size());
else if (url.endsWith(d->gitPostFix))
url.truncate(url.size() - d->gitPostFix.size());
// extract repository name (last part of path)
int startOfRepoName = url.lastIndexOf(slash);
if (startOfRepoName == -1)
startOfRepoName = url.lastIndexOf(QLatin1Char(':'));
url.remove(0, startOfRepoName);
// fix invalid characters
const QChar dash = QLatin1Char('-');
url.replace(QRegExp(QLatin1String("[^0-9a-zA-Z_.-]")), dash);
// trim leading dashes (they are annoying and get created when using local pathes)
url.replace(QRegExp(QLatin1String("^-+")), QString());
return url;
}
QStringList CloneWizardPage::branches(const QString &repository, int *current)
{
// Run git on remote repository if an URL was specified.
*current = -1;
if (repository.isEmpty())
return QStringList();
const QStringList branches = Internal::GitPlugin::instance()->client()->synchronousRepositoryBranches(repository);
if (!branches.isEmpty())
*current = 0; // default branch is always returned first!
return branches;
}
bool CloneWizardPage::isRecursive() const
{
return d->recursiveCheckBox->isChecked();
}
} // namespace Git
#ifdef WITH_TESTS
#include <QTest>
void Git::CloneWizardPage::testDirectoryFromRepository()
{
QFETCH(QString, repository);
QFETCH(QString, localDirectory);
QCOMPARE(directoryFromRepository(repository), localDirectory);
}
#endif

View File

@@ -1,67 +0,0 @@
/****************************************************************************
**
** Copyright (C) 2015 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms and
** conditions see http://www.qt.io/terms-conditions. For further information
** use the contact form at http://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, The Qt Company gives you certain additional
** rights. These rights are described in The Qt Company LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
#ifndef CLONEWIZARDPAGE_H
#define CLONEWIZARDPAGE_H
#include <vcsbase/basecheckoutwizardpage.h>
#include <utils/fileutils.h>
namespace VcsBase { class VcsCommand; }
namespace Git {
struct CloneWizardPagePrivate;
class CloneWizardPage : public VcsBase::BaseCheckoutWizardPage
{
Q_OBJECT
public:
explicit CloneWizardPage(QWidget *parent = 0);
~CloneWizardPage();
QStringList branches(const QString &repository, int *current) override;
bool isRecursive() const;
protected:
QString directoryFromRepository(const QString &r) const override;
#ifdef WITH_TESTS
public:
void testDirectoryFromRepository();
#endif
private:
CloneWizardPagePrivate *d;
};
} // namespace Git
#endif // CLONEWIZARDPAGE_H

View File

@@ -13,8 +13,6 @@ HEADERS += gitplugin.h \
gitsettings.h \
branchdialog.h \
branchmodel.h \
clonewizard.h \
clonewizardpage.h \
stashdialog.h \
gitutils.h \
remotemodel.h \
@@ -38,8 +36,6 @@ SOURCES += gitplugin.cpp \
gitsettings.cpp \
branchdialog.cpp \
branchmodel.cpp \
clonewizard.cpp \
clonewizardpage.cpp \
stashdialog.cpp \
gitutils.cpp \
remotemodel.cpp \

View File

@@ -28,10 +28,6 @@ QtcPlugin {
"changeselectiondialog.cpp",
"changeselectiondialog.h",
"changeselectiondialog.ui",
"clonewizard.cpp",
"clonewizard.h",
"clonewizardpage.cpp",
"clonewizardpage.h",
"commitdata.cpp",
"commitdata.h",
"git.qrc",

View File

@@ -1,6 +1,5 @@
<RCC>
<qresource prefix="/git">
<file>images/git.png</file>
<file>images/arrowup.png</file>
<file>Git.mimetypes.xml</file>
</qresource>

View File

@@ -39,7 +39,6 @@
#include "gitversioncontrol.h"
#include "branchdialog.h"
#include "remotedialog.h"
#include "clonewizard.h"
#include "stashdialog.h"
#include "settingspage.h"
#include "logchangedialog.h"
@@ -86,7 +85,6 @@
#include <QScopedPointer>
#ifdef WITH_TESTS
#include "clonewizardpage.h"
#include <QTest>
#endif
@@ -290,16 +288,6 @@ bool GitPlugin::initialize(const QStringList &arguments, QString *errorMessage)
addAutoReleasedObject(new VcsSubmitEditorFactory(&submitParameters,
[]() { return new GitSubmitEditor(&submitParameters); }));
auto cloneWizardFactory = new BaseCheckoutWizardFactory;
cloneWizardFactory->setId(QLatin1String(VcsBase::Constants::VCS_ID_GIT));
cloneWizardFactory->setIcon(QIcon(QLatin1String(":/git/images/git.png")));
cloneWizardFactory->setDescription(tr("Clones a Git repository and tries to load the contained project."));
cloneWizardFactory->setDisplayName(tr("Git Repository Clone"));
cloneWizardFactory->setWizardCreator([this] (const FileName &path, QWidget *parent) {
return new CloneWizard(path, parent);
});
addAutoReleasedObject(cloneWizardFactory);
const QString prefix = QLatin1String("git");
m_commandLocator = new CommandLocator("Git", prefix, prefix);
addAutoReleasedObject(m_commandLocator);
@@ -1540,27 +1528,6 @@ void GitPlugin::testLogResolving()
"50a6b54c - Merge branch 'for-junio' of git://bogomips.org/git-svn",
"3587b513 - Update draft release notes to 1.8.2");
}
void GitPlugin::testCloneWizard_directoryFromRepository()
{
CloneWizardPage page;
page.testDirectoryFromRepository();
}
void GitPlugin::testCloneWizard_directoryFromRepository_data()
{
QTest::addColumn<QString>("repository");
QTest::addColumn<QString>("localDirectory");
QTest::newRow("http") << "http://host/qt/qt.git" << "qt";
QTest::newRow("without slash") << "user@host:qt.git" << "qt";
QTest::newRow("mainline.git") << "git://gitorious.org/gitorious/mainline.git" << "gitorious";
QTest::newRow("local repo (Unix)") << "/home/user/qt-creator.git" << "qt-creator";
QTest::newRow("local repo (Windows)") << "c:\\repos\\qt-creator.git" << "qt-creator";
QTest::newRow("ssh with port") << "ssh://host:29418/qt/qt.git" << "qt";
QTest::newRow("invalid chars removed") << "ssh://host/in%va$lid.git" << "in-va-lid";
QTest::newRow("leading dashs removed") << "https://gerrit.local/--leadingDash" << "leadingDash";
}
#endif
} // namespace Internal

View File

@@ -143,8 +143,6 @@ private slots:
void testDiffFileResolving_data();
void testDiffFileResolving();
void testLogResolving();
void testCloneWizard_directoryFromRepository();
void testCloneWizard_directoryFromRepository_data();
#endif
protected:
void updateActions(VcsBase::VcsBasePlugin::ActionState) override;

Binary file not shown.

Before

Width:  |  Height:  |  Size: 466 B