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

Method revert

plugins/git/gitplugin.cpp:489–518  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

487
488
489VcsJob* GitPlugin::revert(const QList<QUrl>& localLocations, IBasicVersionControl::RecursionMode recursion)
490{
491 if(localLocations.isEmpty() )
492 return makeVcsErrorJob(i18n("Could not revert changes"), this, OutputJob::Verbose);
493
494 QDir repo = urlDir(repositoryRoot(localLocations.first()));
495 QString modified;
496 for (const auto& file: localLocations) {
497 if (hasModifications(repo, file)) {
498 modified.append(file.toDisplayString(QUrl::PreferLocalFile) + QLatin1String("<br/>"));
499 }
500 }
501 if (!modified.isEmpty()) {
502 auto res = KMessageBox::questionTwoActions(nullptr,
503 i18n("The following files have uncommitted changes, "
504 "which will be lost. Continue?")
505 + QLatin1String("<br/><br/>") + modified,
506 {}, KStandardGuiItem::discard(), KStandardGuiItem::cancel());
507 if (res != KMessageBox::PrimaryAction) {
508 return makeVcsErrorJob(QString(), this, OutputJob::Silent);
509 }
510 }
511
512 DVcsJob* job = new GitJob(dotGitDirectory(localLocations.front()), this);
513 job->setType(VcsJob::Revert);
514 *job << "git" << "checkout" << "--";
515 *job << (recursion == IBasicVersionControl::Recursive ? localLocations : preventRecursion(localLocations));
516
517 return job;
518}
519
520
521//TODO: git doesn't like empty messages, but "KDevelop didn't provide any message, it may be a bug" looks ugly...

Callers 1

revertSelectedFilesMethod · 0.45

Calls 8

dotGitDirectoryFunction · 0.85
preventRecursionFunction · 0.85
urlDirFunction · 0.70
QStringClass · 0.50
isEmptyMethod · 0.45
firstMethod · 0.45
appendMethod · 0.45
setTypeMethod · 0.45

Tested by

no test coverage detected