| 329 | } |
| 330 | |
| 331 | bool DiffTreeModel::discard(const QModelIndex &index) { |
| 332 | assert(index.isValid()); |
| 333 | |
| 334 | Node *node = this->node(index); |
| 335 | QList<int> list; |
| 336 | node->patchIndices(list); |
| 337 | |
| 338 | QStringList trackedPatches; |
| 339 | for (auto i : list) { |
| 340 | auto patch = mDiff.patch(i); |
| 341 | if (patch.isUntracked()) { |
| 342 | QString name = patch.name(); |
| 343 | git::Repository repo = patch.repo(); |
| 344 | QDir dir = repo.workdir(); |
| 345 | if (QFileInfo(dir.filePath(name)).isDir()) { |
| 346 | if (dir.cd(name)) |
| 347 | dir.removeRecursively(); |
| 348 | } else { |
| 349 | dir.remove(name); |
| 350 | } |
| 351 | } else { |
| 352 | trackedPatches.append(patch.name()); |
| 353 | } |
| 354 | } |
| 355 | |
| 356 | auto s = mRepo.submodules(); |
| 357 | QList<git::Submodule> submodules; |
| 358 | QStringList filePatches; |
| 359 | for (auto trackedPatch : trackedPatches) { |
| 360 | bool is_submodule = false; |
| 361 | for (auto submodule : s) { |
| 362 | if (submodule.path() == trackedPatch) { |
| 363 | is_submodule = true; |
| 364 | submodules.append(submodule); |
| 365 | break; |
| 366 | } |
| 367 | } |
| 368 | emit updateSubmodules(submodules, true, false, true); |
| 369 | |
| 370 | if (!is_submodule) |
| 371 | filePatches.append(trackedPatch); |
| 372 | } |
| 373 | |
| 374 | if (filePatches.length() > 0) { |
| 375 | int strategy = GIT_CHECKOUT_FORCE; |
| 376 | auto repo = mDiff.patch(list[0]).repo(); // does not matter which index is |
| 377 | // used all are in the same repo |
| 378 | if (!repo.checkout(git::Commit(), nullptr, trackedPatches, strategy)) |
| 379 | return false; |
| 380 | } |
| 381 | return true; |
| 382 | } |
| 383 | |
| 384 | bool DiffTreeModel::setData(const QModelIndex &index, const QVariant &value, |
| 385 | int role, bool ignoreIndexChanges) { |
nothing calls this directly
no test coverage detected