aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/git/gitplugin.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/git/gitplugin.cpp')
-rw-r--r--src/plugins/git/gitplugin.cpp101
1 files changed, 101 insertions, 0 deletions
diff --git a/src/plugins/git/gitplugin.cpp b/src/plugins/git/gitplugin.cpp
index 87aac67ef09..6d5001ece74 100644
--- a/src/plugins/git/gitplugin.cpp
+++ b/src/plugins/git/gitplugin.cpp
@@ -1552,6 +1552,107 @@ void GitPlugin::testLogResolving()
"50a6b54c - Merge branch 'for-junio' of git://bogomips.org/git-svn",
"3587b513 - Update draft release notes to 1.8.2");
}
+
+class RemoteTest {
+public:
+ RemoteTest() = default;
+ explicit RemoteTest(const QString &url): m_url(url) {}
+
+ inline RemoteTest &protocol(const QString &p) { m_protocol = p; return *this; }
+ inline RemoteTest &userName(const QString &u) { m_userName = u; return *this; }
+ inline RemoteTest &host(const QString &h) { m_host = h; return *this; }
+ inline RemoteTest &port(quint16 p) { m_port = p; return *this; }
+ inline RemoteTest &path(const QString &p) { m_path = p; return *this; }
+ inline RemoteTest &isLocal(bool l) { m_isLocal = l; return *this; }
+ inline RemoteTest &isValid(bool v) { m_isValid = v; return *this; }
+
+ const QString m_url;
+ QString m_protocol;
+ QString m_userName;
+ QString m_host;
+ QString m_path;
+ quint16 m_port = 0;
+ bool m_isLocal = false;
+ bool m_isValid = true;
+};
+
+} // namespace Internal
+} // namespace Git
+
+Q_DECLARE_METATYPE(Git::Internal::RemoteTest)
+
+namespace Git {
+namespace Internal {
+
+void GitPlugin::testGitRemote_data()
+{
+ QTest::addColumn<RemoteTest>("rt");
+
+ QTest::newRow("http-no-user")
+ << RemoteTest("http://code.qt.io/qt-creator/qt-creator.git")
+ .protocol("http")
+ .host("code.qt.io")
+ .path("/qt-creator/qt-creator.git");
+ QTest::newRow("https-with-port")
+ << RemoteTest("https://code.qt.io:80/qt-creator/qt-creator.git")
+ .protocol("https")
+ .host("code.qt.io")
+ .port(80)
+ .path("/qt-creator/qt-creator.git");
+ QTest::newRow("ssh-user-foo")
+ << RemoteTest("ssh://[email protected]:29418/qt-creator/qt-creator.git")
+ .protocol("ssh")
+ .userName("foo")
+ .host("codereview.qt-project.org")
+ .port(29418)
+ .path("/qt-creator/qt-creator.git");
+ QTest::newRow("local-file-protocol")
+ << RemoteTest("file:///tmp/myrepo.git")
+ .protocol("file")
+ .path("/tmp/myrepo.git")
+ .isLocal(true);
+ QTest::newRow("local-absolute-path-unix")
+ << RemoteTest("/tmp/myrepo.git")
+ .protocol("file")
+ .path("/tmp/myrepo.git")
+ .isLocal(true);
+ if (Utils::HostOsInfo::isWindowsHost()) {
+ QTest::newRow("local-absolute-path-unix")
+ << RemoteTest("c:/git/myrepo.git")
+ .protocol("file")
+ .path("c:/git/myrepo.git")
+ .isLocal(true);
+ }
+ QTest::newRow("local-relative-path-children")
+ << RemoteTest("./git/myrepo.git")
+ .protocol("file")
+ .path("./git/myrepo.git")
+ .isLocal(true);
+ QTest::newRow("local-relative-path-parent")
+ << RemoteTest("../myrepo.git")
+ .protocol("file")
+ .path("../myrepo.git")
+ .isLocal(true);
+}
+
+void GitPlugin::testGitRemote()
+{
+ QFETCH(RemoteTest, rt);
+
+ const GitRemote remote = GitRemote(rt.m_url);
+
+ if (!rt.m_isLocal) {
+ // local repositories must exist to be valid, so skip the test
+ QCOMPARE(remote.isValid, rt.m_isValid);
+ }
+
+ QCOMPARE(remote.protocol, rt.m_protocol);
+ QCOMPARE(remote.userName, rt.m_userName);
+ QCOMPARE(remote.host, rt.m_host);
+ QCOMPARE(remote.port, rt.m_port);
+ QCOMPARE(remote.path, rt.m_path);
+}
+
#endif
} // namespace Internal