MCPcopy Create free account
hub / github.com/Murmele/Gittyup / discard

Method discard

src/ui/DiffTreeModel.cpp:331–382  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

329}
330
331bool 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
384bool DiffTreeModel::setData(const QModelIndex &index, const QVariant &value,
385 int role, bool ignoreIndexChanges) {

Callers

nothing calls this directly

Calls 15

nodeMethod · 0.95
patchIndicesMethod · 0.80
patchMethod · 0.80
isUntrackedMethod · 0.80
workdirMethod · 0.80
appendMethod · 0.80
lengthMethod · 0.80
CommitClass · 0.70
isValidMethod · 0.45
nameMethod · 0.45
repoMethod · 0.45
removeMethod · 0.45

Tested by

no test coverage detected