MCPcopy Create free account
hub / github.com/KDE/kdevelop / testStash

Method testStash

plugins/git/tests/test_git.cpp:629–716  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

627}
628
629void 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);

Callers

nothing calls this directly

Calls 15

gitTest_BaseDirFunction · 0.85
writeFileFunction · 0.85
gitTest_FileNameFunction · 0.85
gitTest_FileName2Function · 0.85
allCommitsMethod · 0.80
hasStashesMethod · 0.80
stashListMethod · 0.80
gitStashMethod · 0.80
branchMethod · 0.80
switchBranchMethod · 0.80
runSynchronouslyFunction · 0.50
isEmptyMethod · 0.45

Tested by

no test coverage detected