File indexing completed on 2025-03-09 05:11:39

0001 /*
0002 SPDX-FileCopyrightText: 2022 Laurent Montel <montel@kde.org>
0003 
0004 SPDX-License-Identifier: GPL-3.0-or-later
0005 */
0006 
0007 #include "clonetest.h"
0008 #include "testcommon.h"
0009 #include <entities/commit.h>
0010 #include <entities/tree.h>
0011 
0012 #include <QTest>
0013 #include <gitmanager.h>
0014 
0015 QTEST_GUILESS_MAIN(CloneTest)
0016 
0017 CloneTest::CloneTest(QObject *parent)
0018     : QObject{parent}
0019 {
0020 }
0021 
0022 void CloneTest::initTestCase()
0023 {
0024     auto path = TestCommon::getTempPath();
0025     qDebug() << path;
0026     mManager = new Git::Manager;
0027     QVERIFY(!mManager->isValid());
0028 
0029     TestCommon::initSignature(mManager);
0030 }
0031 
0032 void CloneTest::clone()
0033 {
0034     auto path = TestCommon::getTempPath();
0035     auto ok = mManager->clone("https://invent.kde.org/sdk/kommit.git", path);
0036     QVERIFY(ok);
0037 
0038     path.append("/");
0039     QCOMPARE(path, mManager->path());
0040 
0041     auto tags = mManager->tagsNames();
0042     QVERIFY(tags.contains("v1.0.1"));
0043 }
0044 
0045 void CloneTest::initialCommitTree()
0046 {
0047     auto commit = mManager->commitByHash("05659b9f92b7932bb2c04ced181dbdde294cb0bb");
0048     qDebug() << commit->subject();
0049     QVERIFY(commit);
0050 
0051     auto tree = commit->tree();
0052 
0053     auto topLevelItems = tree->entries("");
0054 
0055     QCOMPARE(topLevelItems.type("snapcraft.yaml"), Git::Tree::EntryType::File);
0056     QCOMPARE(topLevelItems.type("Messages.sh"), Git::Tree::EntryType::File);
0057     QCOMPARE(topLevelItems.type("LICENSE"), Git::Tree::EntryType::File);
0058     QCOMPARE(topLevelItems.type("COPYING.DOC"), Git::Tree::EntryType::File);
0059     QCOMPARE(topLevelItems.type("COPYING"), Git::Tree::EntryType::File);
0060     QCOMPARE(topLevelItems.type("CMakeLists.txt"), Git::Tree::EntryType::File);
0061     QCOMPARE(topLevelItems.type(".gitignore"), Git::Tree::EntryType::File);
0062     QCOMPARE(topLevelItems.type("README.md"), Git::Tree::EntryType::File);
0063 
0064     QCOMPARE(topLevelItems.type("src"), Git::Tree::EntryType::Dir);
0065     QCOMPARE(topLevelItems.type("icons"), Git::Tree::EntryType::Dir);
0066     QCOMPARE(topLevelItems.type("dolphinplugins"), Git::Tree::EntryType::Dir);
0067     QCOMPARE(topLevelItems.type("doc"), Git::Tree::EntryType::Dir);
0068     QCOMPARE(topLevelItems.type("autotests"), Git::Tree::EntryType::Dir);
0069 
0070     auto src = tree->entries("src", Git::Tree::EntryType::Dir);
0071     qDebug() << src;
0072 
0073     QVERIFY(src.contains("widgets"));
0074     QVERIFY(src.contains("settings"));
0075     QVERIFY(src.contains("models"));
0076     QVERIFY(src.contains("merge"));
0077     QVERIFY(src.contains("git"));
0078     QVERIFY(src.contains("diff"));
0079     QVERIFY(src.contains("dialogs"));
0080     QVERIFY(src.contains("core"));
0081     QVERIFY(src.contains("actions"));
0082 }
0083 
0084 void CloneTest::cleanupTestCase()
0085 {
0086     //    TestCommon::cleanPath(mManager);
0087 }
0088 
0089 #include "moc_clonetest.cpp"