File indexing completed on 2024-04-28 04:42:59
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 "qgitrepository.h" 0024 #include "qgitconfig.h" 0025 #include "qgitremote.h" 0026 0027 using namespace LibQGit2; 0028 0029 0030 class TestPush : public TestBase 0031 { 0032 Q_OBJECT 0033 0034 public: 0035 TestPush() : 0036 testdir(VALUE_TO_QSTR(TEST_DIR) + "/push_test/"), 0037 existingRepo(ExistingRepository + "/.git"), 0038 existingBareRepo(ExistingRepository + "_bare") 0039 {} 0040 0041 private slots: 0042 void initTestCase(); 0043 void pushToNewTargetBranch(); 0044 0045 private: 0046 const QString testdir; 0047 const QString existingRepo; 0048 const QString existingBareRepo; 0049 0050 void initBareLocalRepo(); 0051 }; 0052 0053 0054 void TestPush::initTestCase() 0055 { 0056 TestBase::initTestCase(); 0057 0058 initBareLocalRepo(); 0059 } 0060 0061 void TestPush::initBareLocalRepo() 0062 { 0063 removeDir(existingBareRepo); 0064 copyDir(existingRepo, existingBareRepo); 0065 0066 Repository repo; 0067 repo.open(existingBareRepo); 0068 Config cfg = repo.configuration(); 0069 cfg.setValue("core.bare", "true"); 0070 } 0071 0072 0073 void TestPush::pushToNewTargetBranch() 0074 { 0075 const QString repoPath = testdir + "push_new_target_branch"; 0076 QVERIFY(removeDir(repoPath)); 0077 0078 const QString targetBranch("push_new_target_branch"); 0079 0080 Repository repo; 0081 try { 0082 repo.clone(existingBareRepo, repoPath); 0083 QScopedPointer<Remote> remote(repo.remote("origin")); 0084 remote->push(QStringList("refs/heads/master:refs/heads/" + targetBranch)); 0085 } 0086 catch (const LibQGit2::Exception& ex) { 0087 QFAIL(ex.what()); 0088 } 0089 0090 QVERIFY(repo.remoteBranches("origin").contains(targetBranch)); 0091 } 0092 0093 QTEST_MAIN(TestPush) 0094 0095 #include "Push.moc"