| 627 | } |
| 628 | |
| 629 | void GitInitTest::testStash() |
| 630 | { |
| 631 | repoInit(); |
| 632 | addFiles(); |
| 633 | commitFiles(); |
| 634 | const QVector<KDevelop::DVcsEvent> commits = m_plugin->allCommits(gitTest_BaseDir()); |
| 635 | QVERIFY(!commits.isEmpty()); |
| 636 | QStringList logMessages; |
| 637 | |
| 638 | for (auto& commit : commits) |
| 639 | logMessages << commit.log(); |
| 640 | |
| 641 | auto repo_url = QUrl::fromLocalFile(gitTest_BaseDir()); |
| 642 | |
| 643 | // No stash |
| 644 | QVERIFY(!m_plugin->hasStashes(gitTest_BaseDir())); |
| 645 | VcsJob* j = m_plugin->stashList(gitTest_BaseDir()); |
| 646 | VERIFYJOB(j); |
| 647 | QVERIFY(j->fetchResults().value<QList<GitPlugin::StashItem>>().isEmpty()); |
| 648 | |
| 649 | // Do some changes |
| 650 | QVERIFY(writeFile(gitTest_BaseDir() + gitTest_FileName(), QStringLiteral("NEW CONTENT TO STASH"))); |
| 651 | QVERIFY(writeFile(gitTest_BaseDir() + gitTest_FileName2(), QStringLiteral("No, REALLY NEW FOOO()!"))); |
| 652 | |
| 653 | // Verify stashing works |
| 654 | j = m_plugin->gitStash(gitTest_BaseDir(), {}, OutputJob::Silent); |
| 655 | VERIFYJOB(j); |
| 656 | QVERIFY(m_plugin->hasStashes(gitTest_BaseDir())); |
| 657 | |
| 658 | // Verify stash list gives us the single stash |
| 659 | j = m_plugin->stashList(gitTest_BaseDir()); |
| 660 | VERIFYJOB(j); |
| 661 | auto items = j->fetchResults().value<QList<GitPlugin::StashItem>>(); |
| 662 | QVERIFY(items.length() == 1); |
| 663 | QVERIFY(items[0].stackDepth == 0); |
| 664 | QVERIFY(items[0].branch == runSynchronously(m_plugin->currentBranch(repo_url)).toString()); |
| 665 | QVERIFY(commits[0].commit() == items[0].parentSHA); |
| 666 | |
| 667 | // Verify stash on new branch gives us correct parent branch |
| 668 | // |
| 669 | // 1. switch to a new branch |
| 670 | auto rev = KDevelop::VcsRevision::createSpecialRevision(KDevelop::VcsRevision::Head); |
| 671 | j = m_plugin->branch(repo_url, rev, QStringLiteral("my-new-branch")); |
| 672 | VERIFYJOB(j); |
| 673 | j = m_plugin->switchBranch(repo_url, QStringLiteral("my-new-branch")); |
| 674 | VERIFYJOB(j); |
| 675 | |
| 676 | // 2. Do more changes & stash them |
| 677 | QString testFileContent = QStringLiteral("2. NEW CONTENT TO STASH"); |
| 678 | QVERIFY(writeFile(gitTest_BaseDir() + gitTest_FileName(), testFileContent)); |
| 679 | QVERIFY(writeFile(gitTest_BaseDir() + gitTest_FileName2(), QStringLiteral("2. No, REALLY NEW FOOO()!"))); |
| 680 | j = m_plugin->gitStash(gitTest_BaseDir(), {}, OutputJob::Silent); |
| 681 | VERIFYJOB(j); |
| 682 | QFile testFile(gitTest_BaseDir() + gitTest_FileName()); |
| 683 | testFile.open(QIODevice::ReadOnly); |
| 684 | auto testFileContentAfterStash = QString::fromUtf8(testFile.readAll()); |
| 685 | testFile.close(); |
| 686 | QVERIFY(testFileContent != testFileContentAfterStash); |
nothing calls this directly
no test coverage detected