forked from qt-creator/qt-creator
Merge remote-tracking branch 'origin/3.2'
Conflicts: src/plugins/git/gerrit/gerritparameters.cpp src/plugins/git/gerrit/gerritplugin.h src/plugins/git/gitclient.cpp Change-Id: Ie7719cfe45489b72d64260e729dcce3760f33bec
This commit is contained in:
@@ -44,14 +44,12 @@ struct CloneWizardPagePrivate {
|
||||
|
||||
const QString mainLinePostfix;
|
||||
const QString gitPostFix;
|
||||
const QString protocolDelimiter;
|
||||
QCheckBox *recursiveCheckBox;
|
||||
};
|
||||
|
||||
CloneWizardPagePrivate::CloneWizardPagePrivate() :
|
||||
mainLinePostfix(QLatin1String("/mainline.git")),
|
||||
gitPostFix(QLatin1String(".git")),
|
||||
protocolDelimiter(QLatin1String("://")),
|
||||
recursiveCheckBox(0)
|
||||
{
|
||||
}
|
||||
@@ -83,33 +81,21 @@ CloneWizardPage::~CloneWizardPage()
|
||||
|
||||
QString CloneWizardPage::directoryFromRepository(const QString &urlIn) const
|
||||
{
|
||||
/* Try to figure out a good directory name from something like:
|
||||
* 'user@host:qt/qt.git', 'http://host/qt/qt.git' 'local repo'
|
||||
* ------> 'qt' . */
|
||||
const QChar slash = QLatin1Char('/');
|
||||
QString url = urlIn.trimmed().replace(QLatin1Char('\\'), slash);
|
||||
|
||||
// remove host
|
||||
const int protocolDelimiterPos = url.indexOf(d->protocolDelimiter); // "://"
|
||||
const int startRepoSearchPos = protocolDelimiterPos == -1 ? 0 : protocolDelimiterPos + d->protocolDelimiter.size();
|
||||
int repoPos = url.indexOf(QLatin1Char(':'), startRepoSearchPos);
|
||||
if (repoPos == -1)
|
||||
repoPos = url.indexOf(slash, startRepoSearchPos);
|
||||
if (repoPos != -1)
|
||||
url.remove(0, repoPos + 1);
|
||||
// Remove postfixes
|
||||
if (url.endsWith(d->mainLinePostfix)) {
|
||||
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());
|
||||
}
|
||||
// Check for equal parts, something like "qt/qt" -> "qt"
|
||||
const int slashPos = url.indexOf(slash);
|
||||
if (slashPos != -1 && slashPos == (url.size() - 1) / 2) {
|
||||
if (url.leftRef(slashPos) == url.rightRef(slashPos))
|
||||
url.truncate(slashPos);
|
||||
}
|
||||
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);
|
||||
@@ -154,3 +140,15 @@ QStringList CloneWizardPage::branches(const QString &repository, int *current)
|
||||
}
|
||||
|
||||
} // namespace Git
|
||||
|
||||
#ifdef WITH_TESTS
|
||||
#include <QTest>
|
||||
|
||||
void Git::CloneWizardPage::testDirectoryFromRepository()
|
||||
{
|
||||
QFETCH(QString, repository);
|
||||
QFETCH(QString, localDirectory);
|
||||
|
||||
QCOMPARE(directoryFromRepository(repository), localDirectory);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -54,6 +54,11 @@ protected:
|
||||
QString directoryFromRepository(const QString &r) const;
|
||||
QStringList branches(const QString &repository, int *current);
|
||||
|
||||
#ifdef WITH_TESTS
|
||||
public:
|
||||
void testDirectoryFromRepository();
|
||||
#endif
|
||||
|
||||
private:
|
||||
CloneWizardPagePrivate *d;
|
||||
};
|
||||
|
||||
@@ -73,14 +73,9 @@ static inline QString detectSsh()
|
||||
if (!ssh.isEmpty())
|
||||
return ssh;
|
||||
if (Utils::HostOsInfo::isWindowsHost()) { // Windows: Use ssh.exe from git if it cannot be found.
|
||||
const Utils::FileName git = GerritPlugin::gitBinary();
|
||||
if (!git.isEmpty()) {
|
||||
// Is 'git\cmd' in the path (folder containing .bats)?
|
||||
QString path = git.parentDir().toString();
|
||||
if (path.endsWith(QLatin1String("cmd"), Qt::CaseInsensitive))
|
||||
path.replace(path.size() - 3, 3, QLatin1String("bin"));
|
||||
ssh = path + QLatin1Char('/') + QLatin1String(defaultSshC);
|
||||
}
|
||||
Utils::FileName path = GerritPlugin::gitBinDirectory();
|
||||
if (!path.isEmpty())
|
||||
ssh = path.appendPath(QLatin1String(defaultSshC)).toString();
|
||||
}
|
||||
return ssh;
|
||||
}
|
||||
|
||||
@@ -399,6 +399,11 @@ Utils::FileName GerritPlugin::gitBinary()
|
||||
return git;
|
||||
}
|
||||
|
||||
Utils::FileName GerritPlugin::gitBinDirectory()
|
||||
{
|
||||
return gitClient()->gitBinDirectory();
|
||||
}
|
||||
|
||||
// Find the branch of a repository.
|
||||
QString GerritPlugin::branch(const QString &repository)
|
||||
{
|
||||
|
||||
@@ -64,6 +64,7 @@ public:
|
||||
bool initialize(Core::ActionContainer *ac);
|
||||
|
||||
static Utils::FileName gitBinary();
|
||||
static Utils::FileName gitBinDirectory();
|
||||
static QString branch(const QString &repository);
|
||||
void addToLocator(Core::CommandLocator *locator);
|
||||
void push(const QString &topLevel);
|
||||
|
||||
@@ -2639,6 +2639,24 @@ bool GitClient::launchGitGui(const QString &workingDirectory) {
|
||||
return success;
|
||||
}
|
||||
|
||||
Utils::FileName GitClient::gitBinDirectory()
|
||||
{
|
||||
const QString git = gitBinaryPath();
|
||||
if (git.isEmpty())
|
||||
return Utils::FileName();
|
||||
|
||||
// Is 'git\cmd' in the path (folder containing .bats)?
|
||||
QString path = QFileInfo(git).absolutePath();
|
||||
// Git for Windows (msysGit) has git and gitk redirect executables in {setup dir}/cmd
|
||||
// and the real binaries are in {setup dir}/bin. If cmd is configured in PATH
|
||||
// or in Git settings, return bin instead.
|
||||
if (Utils::HostOsInfo::isWindowsHost()
|
||||
&& path.endsWith(QLatin1String("/cmd"), Utils::HostOsInfo::fileNameCaseSensitivity())) {
|
||||
path.replace(path.size() - 3, 3, QLatin1String("bin"));
|
||||
}
|
||||
return Utils::FileName::fromString(path);
|
||||
}
|
||||
|
||||
Utils::FileName GitClient::gitBinaryPath(bool *ok, QString *errorMessage) const
|
||||
{
|
||||
return settings()->gitBinaryPath(ok, errorMessage);
|
||||
|
||||
@@ -35,6 +35,8 @@
|
||||
|
||||
#include <coreplugin/editormanager/ieditor.h>
|
||||
|
||||
#include <utils/fileutils.h>
|
||||
|
||||
#include <QFutureSynchronizer>
|
||||
#include <QObject>
|
||||
#include <QString>
|
||||
@@ -315,6 +317,7 @@ public:
|
||||
void launchGitK(const QString &workingDirectory, const QString &fileName);
|
||||
void launchGitK(const QString &workingDirectory) { launchGitK(workingDirectory, QString()); }
|
||||
bool launchGitGui(const QString &workingDirectory);
|
||||
Utils::FileName gitBinDirectory();
|
||||
|
||||
void launchRepositoryBrowser(const QString &workingDirectory);
|
||||
|
||||
|
||||
@@ -1041,7 +1041,9 @@ Core::IEditor *GitPlugin::openSubmitEditor(const QString &fileName, const Commit
|
||||
default:
|
||||
title = tr("Git Commit");
|
||||
}
|
||||
submitEditor->document()->setDisplayName(title);
|
||||
Core::IDocument *document = submitEditor->document();
|
||||
document->setDisplayName(title);
|
||||
VcsBasePlugin::setSource(document, m_submitRepository);
|
||||
connect(submitEditor, SIGNAL(diff(QStringList,QStringList)), this, SLOT(submitEditorDiff(QStringList,QStringList)));
|
||||
connect(submitEditor, SIGNAL(merge(QStringList)), this, SLOT(submitEditorMerge(QStringList)));
|
||||
connect(submitEditor, SIGNAL(show(QString,QString)), m_gitClient, SLOT(show(QString,QString)));
|
||||
@@ -1487,6 +1489,8 @@ Gerrit::Internal::GerritPlugin *GitPlugin::gerritPlugin() const
|
||||
|
||||
#ifdef WITH_TESTS
|
||||
|
||||
#include "clonewizardpage.h"
|
||||
|
||||
#include <QTest>
|
||||
|
||||
Q_DECLARE_METATYPE(FileStates)
|
||||
@@ -1602,6 +1606,27 @@ 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
|
||||
|
||||
Q_EXPORT_PLUGIN(GitPlugin)
|
||||
|
||||
@@ -149,6 +149,8 @@ private slots:
|
||||
void testDiffFileResolving_data();
|
||||
void testDiffFileResolving();
|
||||
void testLogResolving();
|
||||
void testCloneWizard_directoryFromRepository();
|
||||
void testCloneWizard_directoryFromRepository_data();
|
||||
#endif
|
||||
protected:
|
||||
void updateActions(VcsBase::VcsBasePlugin::ActionState);
|
||||
|
||||
@@ -154,7 +154,11 @@ QString GitVersionControl::vcsTopic(const QString &directory)
|
||||
|
||||
QStringList GitVersionControl::additionalToolsPath() const
|
||||
{
|
||||
return m_client->settings()->searchPathList();
|
||||
QStringList res = m_client->settings()->searchPathList();
|
||||
const QString binaryPath = m_client->gitBinDirectory().toString();
|
||||
if (!binaryPath.isEmpty() && !res.contains(binaryPath))
|
||||
res << binaryPath;
|
||||
return res;
|
||||
}
|
||||
|
||||
bool GitVersionControl::managesDirectory(const QString &directory, QString *topLevel) const
|
||||
|
||||
Reference in New Issue
Block a user