Git: Suggest to force-push on non-fast-forward failure

Fixes: QTCREATORBUG-21630
Change-Id: I31564d3909a1e3a3a66daf58323952944d5847f9
Reviewed-by: André Hartmann <aha_1980@gmx.de>
Reviewed-by: Leena Miettinen <riitta-leena.miettinen@qt.io>
This commit is contained in:
Orgad Shaneh
2019-03-25 16:56:19 +02:00
committed by Orgad Shaneh
parent 1787715165
commit 1333b695d4

View File

@@ -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 <span style=\"color:#%1\">"
"(rewrites remote history)</span>?")
.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,