| 482 | } |
| 483 | |
| 484 | void DiffWidget::applyDiff(const QString &diff, ApplyFlags flags) |
| 485 | { |
| 486 | // const QString diff = getDiff(v, flags & Hunk, flags & (Staged | Discard)); |
| 487 | if (diff.isEmpty()) { |
| 488 | return; |
| 489 | } |
| 490 | |
| 491 | auto *file = new QTemporaryFile(this); |
| 492 | if (!file->open()) { |
| 493 | // sendMessage(i18n("Failed to stage selection"), true); |
| 494 | return; |
| 495 | } |
| 496 | file->write(diff.toUtf8()); |
| 497 | file->close(); |
| 498 | |
| 499 | Q_ASSERT(!m_params.workingDir.isEmpty()); |
| 500 | auto *git = new QProcess(this); |
| 501 | QStringList args; |
| 502 | if (flags & Discard) { |
| 503 | args = QStringList{QStringLiteral("apply"), file->fileName()}; |
| 504 | } else { |
| 505 | args = QStringList{QStringLiteral("apply"), QStringLiteral("--index"), QStringLiteral("--cached"), file->fileName()}; |
| 506 | } |
| 507 | if (!setupGitProcess(*git, m_params.workingDir, args)) { |
| 508 | gitNotFoundMessage(); |
| 509 | return; |
| 510 | } |
| 511 | |
| 512 | connect(git, &QProcess::finished, this, [this, git, file](int exitCode, QProcess::ExitStatus es) { |
| 513 | if (es != QProcess::NormalExit || exitCode != 0) { |
| 514 | onError(git->readAllStandardError(), git->exitCode()); |
| 515 | } else { |
| 516 | runGitDiff(); |
| 517 | if (m_params.updateStatusCallback) { |
| 518 | m_params.updateStatusCallback(); |
| 519 | } |
| 520 | } |
| 521 | delete file; |
| 522 | git->deleteLater(); |
| 523 | }); |
| 524 | startHostProcess(*git, QProcess::ReadOnly); |
| 525 | } |
| 526 | |
| 527 | void DiffWidget::runGitDiff() |
| 528 | { |
nothing calls this directly
no test coverage detected