diff --git a/src/plugins/vcsbase/submiteditorwidget.cpp b/src/plugins/vcsbase/submiteditorwidget.cpp index ad15a8ca9b0..38ffe003d59 100644 --- a/src/plugins/vcsbase/submiteditorwidget.cpp +++ b/src/plugins/vcsbase/submiteditorwidget.cpp @@ -29,6 +29,7 @@ #include "ui_submiteditorwidget.h" #include +#include #include #include @@ -503,9 +504,59 @@ void SubmitEditorWidget::hideDescription() setDescriptionMandatory(false); } +void VcsBase::SubmitEditorWidget::verifyDescription() +{ + auto fontColor = [](Utils::Theme::Color color) { + return QString("") + .arg(Utils::creatorTheme()->color(color).name()); + }; + const QString hint = fontColor(Utils::Theme::OutputPanes_TestWarnTextColor); + const QString warning = fontColor(Utils::Theme::TextColorError); + + const QChar newLine = '\n'; + const int descriptionLength = d->m_description.length(); + int subjectLength = d->m_description.indexOf(newLine); + int secondLineLength = 0; + if (subjectLength >= 0) { + const int secondLineStart = subjectLength + 1; + secondLineLength = d->m_description.indexOf(newLine, secondLineStart) + - secondLineStart; + } else { + subjectLength = descriptionLength; + } + + enum { MaxSubjectLength = 72, WarningSubjectLength = 55 }; + QStringList hints; + QStringList toolTips; + if (descriptionLength < 20) + hints.append(warning + tr("Warning: The commit message is very short.")); + + if (subjectLength > MaxSubjectLength) + hints.append(warning + tr("Warning: The commit subject is too long.")); + else if (subjectLength > WarningSubjectLength) + hints.append(hint + tr("Hint: Aim for a shorter commit subject.")); + + if (secondLineLength > 0) + hints.append(hint + tr("Hint: The second line of a commit message should be empty.")); + + d->m_ui.descriptionHint->setText(hints.join("
")); + if (!d->m_ui.descriptionHint->text().isEmpty()) { + d->m_ui.descriptionHint->setToolTip( + tr("

Writing good commit messages

" + "
    " + "
  • Avoid very short commit messages.
  • " + "
  • Consider the first line as subject (like in email) " + "and keep it shorter than %1 characters.
  • " + "
  • After an empty second line, a longer description can be added.
  • " + "
  • Describe why the change was done, not how it was done.
  • " + "
").arg(MaxSubjectLength)); + } +} + void SubmitEditorWidget::descriptionTextChanged() { d->m_description = cleanupDescription(d->m_ui.description->toPlainText()); + verifyDescription(); wrapDescription(); trimDescription(); // append field entries diff --git a/src/plugins/vcsbase/submiteditorwidget.h b/src/plugins/vcsbase/submiteditorwidget.h index e19ab65c4de..ceec8c3d340 100644 --- a/src/plugins/vcsbase/submiteditorwidget.h +++ b/src/plugins/vcsbase/submiteditorwidget.h @@ -137,6 +137,7 @@ private: int checkedFilesCount() const; void wrapDescription(); void trimDescription(); + void verifyDescription(); SubmitEditorWidgetPrivate *d; }; diff --git a/src/plugins/vcsbase/submiteditorwidget.ui b/src/plugins/vcsbase/submiteditorwidget.ui index 9479930ec1e..b1ff57522c7 100644 --- a/src/plugins/vcsbase/submiteditorwidget.ui +++ b/src/plugins/vcsbase/submiteditorwidget.ui @@ -90,6 +90,16 @@ true + + + + + + + true + + +