From 1333b695d4453729a94bea8eff3a88f2f76c84a1 Mon Sep 17 00:00:00 2001 From: Orgad Shaneh Date: Mon, 25 Mar 2019 16:56:19 +0200 Subject: [PATCH] Git: Suggest to force-push on non-fast-forward failure MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes: QTCREATORBUG-21630 Change-Id: I31564d3909a1e3a3a66daf58323952944d5847f9 Reviewed-by: André Hartmann Reviewed-by: Leena Miettinen --- src/plugins/git/gitclient.cpp | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/src/plugins/git/gitclient.cpp b/src/plugins/git/gitclient.cpp index 584349b26d1..b28990b7143 100644 --- a/src/plugins/git/gitclient.cpp +++ b/src/plugins/git/gitclient.cpp @@ -3024,8 +3024,29 @@ void GitClient::subversionDeltaCommit(const QString &workingDirectory) void GitClient::push(const QString &workingDirectory, const QStringList &pushArgs) { - vcsExec(workingDirectory, QStringList({"push"}) + pushArgs, nullptr, true, - VcsCommand::ShowSuccessMessage); + VcsCommand *command = vcsExec( + workingDirectory, QStringList({"push"}) + pushArgs, nullptr, true, + VcsCommand::ShowSuccessMessage); + connect(command, &VcsCommand::stdErrText, this, [command](const QString &text) { + if (text.contains("non-fast-forward")) + command->setCookie(true); + }); + connect(command, &VcsCommand::finished, + this, [this, command, workingDirectory, pushArgs](bool success) { + if (!success && command->cookie().toBool()) { + const QColor warnColor = Utils::creatorTheme()->color(Theme::TextColorError); + if (QMessageBox::question( + Core::ICore::dialogParent(), tr("Force Push"), + tr("Push failed. Would you like to force-push " + "(rewrites remote history)?") + .arg(QString::number(warnColor.rgba(), 16)), + QMessageBox::Yes | QMessageBox::No, + QMessageBox::No) == QMessageBox::Yes) { + vcsExec(workingDirectory, QStringList({"push", "--force-with-lease"}) + pushArgs, + nullptr, true, VcsCommand::ShowSuccessMessage); + } + } + }); } bool GitClient::synchronousMerge(const QString &workingDirectory, const QString &branch,