Warning, file /libraries/libqgit2/tests/Rebase.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 /****************************************************************************** 0002 * Permission to use, copy, modify, and distribute the software 0003 * and its documentation for any purpose and without fee is hereby 0004 * granted, provided that the above copyright notice appear in all 0005 * copies and that both that the copyright notice and this 0006 * permission notice and warranty disclaimer appear in supporting 0007 * documentation, and that the name of the author not be used in 0008 * advertising or publicity pertaining to distribution of the 0009 * software without specific, written prior permission. 0010 * 0011 * The author disclaim all warranties with regard to this 0012 * software, including all implied warranties of merchantability 0013 * and fitness. In no event shall the author be liable for any 0014 * special, indirect or consequential damages or any damages 0015 * whatsoever resulting from loss of use, data or profits, whether 0016 * in an action of contract, negligence or other tortious action, 0017 * arising out of or in connection with the use or performance of 0018 * this software. 0019 */ 0020 0021 #include "TestHelpers.h" 0022 0023 #include "qgitindex.h" 0024 #include "qgitrebase.h" 0025 #include "qgitremote.h" 0026 #include "qgitrepository.h" 0027 #include "qgitrevwalk.h" 0028 #include "qgitdiff.h" 0029 #include "qgitdiffdelta.h" 0030 #include "qgittree.h" 0031 0032 #include <QFile> 0033 #include <QFileInfo> 0034 #include <QPointer> 0035 0036 using namespace LibQGit2; 0037 0038 class TestRebase : public TestBase 0039 { 0040 Q_OBJECT 0041 public: 0042 TestRebase(); 0043 0044 private slots: 0045 void init(); 0046 void cleanup(); 0047 0048 void TestRebasingMasterOntoAnotherBranchProducesCorrectTopology(); 0049 0050 private: 0051 QSharedPointer<Repository> repo; 0052 Signature sig; 0053 0054 OId commitIndexToRef(const QString &refSpec); 0055 void writeToIndex(const QString &path, const QString &text); 0056 }; 0057 0058 TestRebase::TestRebase() 0059 : TestBase(), 0060 sig("unknown", "unknown") 0061 { 0062 } 0063 0064 void TestRebase::init() 0065 { 0066 TestBase::init(); 0067 initTestRepo(); 0068 repo = QSharedPointer<Repository>(new Repository); 0069 repo->open(testdir + "/.git"); 0070 } 0071 0072 void TestRebase::cleanup() 0073 { 0074 repo.clear(); 0075 TestBase::cleanup(); 0076 } 0077 0078 OId TestRebase::commitIndexToRef(const QString &refSpec) 0079 { 0080 Tree index = repo->lookupTree(repo->index().createTree()); 0081 QList<Commit> parents; 0082 parents.append(repo->lookupCommit(repo->head().target())); 0083 return repo->createCommit(index, parents, sig, sig, "commit", refSpec); 0084 } 0085 0086 void TestRebase::writeToIndex(const QString &path, const QString &text) 0087 { 0088 QFile file(path); 0089 file.open(QFile::ReadWrite); 0090 file.write(text.toUtf8()); 0091 file.close(); 0092 repo->index().addByPath(QFileInfo(path).fileName()); 0093 repo->index().write(); 0094 } 0095 0096 void TestRebase::TestRebasingMasterOntoAnotherBranchProducesCorrectTopology() 0097 { 0098 // set up the repository 0099 QString refSpecOntoBranch("refs/heads/onto"); 0100 repo->createBranch("onto"); 0101 QString pathOntoBranchFile(testdir + "/onto.txt"); 0102 writeToIndex(pathOntoBranchFile, "testing"); 0103 OId oidOntoCommit = commitIndexToRef(refSpecOntoBranch); 0104 0105 repo->checkoutHead(CheckoutOptions(CheckoutOptions::Force)); 0106 0107 QString pathMasterBranchFile(testdir + "/master.txt"); 0108 writeToIndex(pathMasterBranchFile, "testing testing"); 0109 commitIndexToRef("HEAD"); 0110 0111 // rebase master onto another branch 0112 Reference refOnto = repo->lookupRef(refSpecOntoBranch); 0113 Reference refMaster = repo->lookupRef("refs/heads/master"); 0114 Reference refUpstream = repo->lookupRef("refs/remotes/origin/master"); 0115 Rebase rebase = repo->rebase(refMaster, refUpstream, refOnto, RebaseOptions(CheckoutOptions(CheckoutOptions::Safe, CheckoutOptions::RecreateMissing))); 0116 rebase.next(); 0117 OId oidRebasedMaster = rebase.commit(sig, sig, QString()); 0118 rebase.finish(sig); 0119 0120 // check results 0121 RevWalk walk(*repo); 0122 walk.setSorting(RevWalk::Topological); 0123 walk.pushHead(); 0124 OId oid; 0125 QVERIFY(walk.next(oid)); 0126 QCOMPARE(oidRebasedMaster, oid); 0127 QVERIFY(walk.next(oid)); 0128 QCOMPARE(oidOntoCommit, oid); 0129 QVERIFY(walk.next(oid)); 0130 QCOMPARE(refUpstream.target(), oid); 0131 } 0132 0133 0134 QTEST_MAIN(TestRebase); 0135 0136 #include "Rebase.moc"