From f6bfd7532047c2ca538d8de5ea33b06db92be668 Mon Sep 17 00:00:00 2001 From: Andre Hartmann Date: Sun, 13 Jul 2014 13:12:12 +0200 Subject: [PATCH] Git: Fix suggested directory for clone For: * remote paths with port number * local repositories Task-number: QTCREATORBUG-12651 Change-Id: I7fef5c78499291047781ab48a7fef31d52613198 Reviewed-by: Orgad Shaneh Reviewed-by: Friedemann Kleint Reviewed-by: Tobias Hunger --- src/plugins/git/clonewizardpage.cpp | 35 +++++++++-------------------- src/plugins/git/gitplugin.cpp | 8 +++++-- 2 files changed, 16 insertions(+), 27 deletions(-) diff --git a/src/plugins/git/clonewizardpage.cpp b/src/plugins/git/clonewizardpage.cpp index 5b1565dd066..ad942e57ae2 100644 --- a/src/plugins/git/clonewizardpage.cpp +++ b/src/plugins/git/clonewizardpage.cpp @@ -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); @@ -163,7 +149,6 @@ void Git::CloneWizardPage::testDirectoryFromRepository() QFETCH(QString, repository); QFETCH(QString, localDirectory); - QEXPECT_FAIL("ssh with port", "QTCREATORBUG-12651", Abort); QCOMPARE(directoryFromRepository(repository), localDirectory); } #endif diff --git a/src/plugins/git/gitplugin.cpp b/src/plugins/git/gitplugin.cpp index ea0d8a06074..9ee1fe321ff 100644 --- a/src/plugins/git/gitplugin.cpp +++ b/src/plugins/git/gitplugin.cpp @@ -1619,9 +1619,13 @@ void GitPlugin::testCloneWizard_directoryFromRepository_data() QTest::addColumn("localDirectory"); QTest::newRow("http") << "http://host/qt/qt.git" << "qt"; - QTest::newRow("user@host") << "user@host:qt/qt.git" << "qt"; - QTest::newRow("local repo") << "/home/user/qt-creator.git" << "home-user-qt-creator"; + 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