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

Method commitFiles

plugins/git/tests/test_git.cpp:197–258  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

195}
196
197void GitInitTest::commitFiles()
198{
199 qDebug() << "Committing...";
200 //we start it after addFiles, so we just have to commit
201 VcsJob* j = m_plugin->commit(QStringLiteral("Test commit"), QList<QUrl>() << QUrl::fromLocalFile(gitTest_BaseDir()));
202 VERIFYJOB(j);
203
204 //test git-status exitCode one more time.
205 j = m_plugin->status(QList<QUrl>() << QUrl::fromLocalFile(gitTest_BaseDir()));
206 VERIFYJOB(j);
207
208 //since we committed the file to the "pure" repository, .git/refs/heads/master should exist
209 //TODO: maybe other method should be used
210 QString headRefName(gitRepo() + "/refs/heads/master");
211 QVERIFY(QFileInfo::exists(headRefName));
212
213 //Test the results of the "git add"
214 auto* jobLs = new DVcsJob(gitTest_BaseDir(), m_plugin);
215 *jobLs << "git" << "ls-tree" << "--name-only" << "-r" << "HEAD";
216
217 if (jobLs->exec() && jobLs->status() == KDevelop::VcsJob::JobSucceeded) {
218 QStringList files = jobLs->output().split('\n');
219 QVERIFY(files.contains(gitTest_FileName()));
220 QVERIFY(files.contains(gitTest_FileName2()));
221 QVERIFY(files.contains("src/" + gitTest_FileName3()));
222 }
223
224 QString firstCommit;
225
226 QFile headRef(headRefName);
227
228 if (headRef.open(QIODevice::ReadOnly)) {
229 QTextStream output(&headRef);
230 output >> firstCommit;
231 }
232 headRef.close();
233
234 QVERIFY(!firstCommit.isEmpty());
235
236 qDebug() << "Committing one more time";
237 //let's try to change the file and test "git commit -a"
238 QVERIFY(writeFile(gitTest_BaseDir() + gitTest_FileName(), QStringLiteral("Just another HELLO WORLD\n")));
239
240 //add changes
241 j = m_plugin->add(QList<QUrl>() << QUrl::fromLocalFile(gitTest_BaseDir() + gitTest_FileName()));
242 VERIFYJOB(j);
243
244 j = m_plugin->commit(QStringLiteral("KDevelop's Test commit2"), QList<QUrl>() << QUrl::fromLocalFile(gitTest_BaseDir()));
245 VERIFYJOB(j);
246
247 QString secondCommit;
248
249 if (headRef.open(QIODevice::ReadOnly)) {
250 QTextStream output(&headRef);
251 output >> secondCommit;
252 }
253 headRef.close();
254

Callers

nothing calls this directly

Calls 15

gitTest_BaseDirFunction · 0.85
gitRepoFunction · 0.85
gitTest_FileNameFunction · 0.85
gitTest_FileName2Function · 0.85
gitTest_FileName3Function · 0.85
writeFileFunction · 0.85
execMethod · 0.80
outputMethod · 0.80
commitMethod · 0.45
statusMethod · 0.45
splitMethod · 0.45
containsMethod · 0.45

Tested by

no test coverage detected