forked from qt-creator/qt-creator
VCS: Add commit message verification
Help writing good commit messages by verifying that the complete message is not too short, that the first line (subject) is not too long and that the subject is separated from the rest of the commit by an empty line. Change-Id: I296c036433767f2508630f409c0e4b4c241391d1 Reviewed-by: Leena Miettinen <riitta-leena.miettinen@qt.io> Reviewed-by: Orgad Shaneh <orgads@gmail.com>
This commit is contained in:
committed by
André Hartmann
parent
b4c1e48fdc
commit
8c92f40db8
@@ -29,6 +29,7 @@
|
|||||||
#include "ui_submiteditorwidget.h"
|
#include "ui_submiteditorwidget.h"
|
||||||
|
|
||||||
#include <utils/algorithm.h>
|
#include <utils/algorithm.h>
|
||||||
|
#include <utils/theme/theme.h>
|
||||||
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QPointer>
|
#include <QPointer>
|
||||||
@@ -503,9 +504,59 @@ void SubmitEditorWidget::hideDescription()
|
|||||||
setDescriptionMandatory(false);
|
setDescriptionMandatory(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void VcsBase::SubmitEditorWidget::verifyDescription()
|
||||||
|
{
|
||||||
|
auto fontColor = [](Utils::Theme::Color color) {
|
||||||
|
return QString("<font color=\"%1\">")
|
||||||
|
.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("<br>"));
|
||||||
|
if (!d->m_ui.descriptionHint->text().isEmpty()) {
|
||||||
|
d->m_ui.descriptionHint->setToolTip(
|
||||||
|
tr("<p>Writing good commit messages</p>"
|
||||||
|
"<ul>"
|
||||||
|
"<li>Avoid very short commit messages.</li>"
|
||||||
|
"<li>Consider the first line as subject (like in email) "
|
||||||
|
"and keep it shorter than %1 characters.</li>"
|
||||||
|
"<li>After an empty second line, a longer description can be added.</li>"
|
||||||
|
"<li>Describe why the change was done, not how it was done.</li>"
|
||||||
|
"</ul>").arg(MaxSubjectLength));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void SubmitEditorWidget::descriptionTextChanged()
|
void SubmitEditorWidget::descriptionTextChanged()
|
||||||
{
|
{
|
||||||
d->m_description = cleanupDescription(d->m_ui.description->toPlainText());
|
d->m_description = cleanupDescription(d->m_ui.description->toPlainText());
|
||||||
|
verifyDescription();
|
||||||
wrapDescription();
|
wrapDescription();
|
||||||
trimDescription();
|
trimDescription();
|
||||||
// append field entries
|
// append field entries
|
||||||
|
@@ -137,6 +137,7 @@ private:
|
|||||||
int checkedFilesCount() const;
|
int checkedFilesCount() const;
|
||||||
void wrapDescription();
|
void wrapDescription();
|
||||||
void trimDescription();
|
void trimDescription();
|
||||||
|
void verifyDescription();
|
||||||
|
|
||||||
SubmitEditorWidgetPrivate *d;
|
SubmitEditorWidgetPrivate *d;
|
||||||
};
|
};
|
||||||
|
@@ -90,6 +90,16 @@
|
|||||||
<bool>true</bool>
|
<bool>true</bool>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QVBoxLayout" name="descriptionLayout">
|
<layout class="QVBoxLayout" name="descriptionLayout">
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="descriptionHint">
|
||||||
|
<property name="text">
|
||||||
|
<string/>
|
||||||
|
</property>
|
||||||
|
<property name="wordWrap">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="Utils::CompletingTextEdit" name="description">
|
<widget class="Utils::CompletingTextEdit" name="description">
|
||||||
<property name="acceptRichText">
|
<property name="acceptRichText">
|
||||||
|
Reference in New Issue
Block a user