From 366b813c5c8e92788777bbb3e58a36c9b7da26b2 Mon Sep 17 00:00:00 2001 From: Orgad Shaneh Date: Mon, 30 Apr 2018 17:20:11 +0300 Subject: [PATCH] Gerrit: Warn when probably pushing to wrong branch For rebase/merge strategies, this can cause real problems (when the target branch is forwarded to a more recent branch...) Task-number: QTCREATORBUG-20062 Change-Id: Ic7c282a1e0571b31d9333290141817c59daa0e7a Reviewed-by: Tobias Hunger --- src/plugins/git/gerrit/gerritpushdialog.cpp | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/plugins/git/gerrit/gerritpushdialog.cpp b/src/plugins/git/gerrit/gerritpushdialog.cpp index 17e36c4fd25..622da381793 100644 --- a/src/plugins/git/gerrit/gerritpushdialog.cpp +++ b/src/plugins/git/gerrit/gerritpushdialog.cpp @@ -32,7 +32,9 @@ #include "../gitconstants.h" #include +#include +#include #include #include #include @@ -44,6 +46,8 @@ using namespace Git::Internal; namespace Gerrit { namespace Internal { +static const int ReasonableDistance = 100; + class PushItemDelegate : public IconItemDelegate { public: @@ -207,8 +211,18 @@ void GerritPushDialog::setChangeRange() } m_ui->infoLabel->show(); const QString remote = selectedRemoteName() + '/' + remoteBranchName; - m_ui->infoLabel->setText( - tr("Number of commits between %1 and %2: %3").arg(branch, remote, range)); + QString labelText = tr("Number of commits between %1 and %2: %3").arg(branch, remote, range); + const int currentRange = range.toInt(); + QPalette palette = QApplication::palette(); + if (currentRange > ReasonableDistance) { + const QColor errorColor = Utils::creatorTheme()->color(Utils::Theme::TextColorError); + palette.setColor(QPalette::Foreground, errorColor); + palette.setColor(QPalette::ButtonText, errorColor); + labelText.append("\n" + tr("Are you sure you selected the right target branch?")); + } + m_ui->infoLabel->setPalette(palette); + m_ui->targetBranchComboBox->setPalette(palette); + m_ui->infoLabel->setText(labelText); } static bool versionSupportsWip(const QString &version)