Skip to content
Snippets Groups Projects
Commit d1976d19 authored by Tobias Hunger's avatar Tobias Hunger
Browse files

Git: Only enable submit button when a description is available

Only enable submit button in the git submit editor when a non-empty
desciption of the patch is available. Git rejects empty commit messages
and old versions fail without even giving an error Qt Creator can detect,
so this should make commiting a bit more save.

Task-number: QTCREATORBUG-2410
parent 2f07660e
No related branches found
No related tags found
No related merge requests found
......@@ -172,6 +172,8 @@ SubmitEditorWidget::SubmitEditorWidget(QWidget *parent) :
m_d->m_ui.description->setWordWrapMode(QTextOption::WordWrap);
connect(m_d->m_ui.description, SIGNAL(customContextMenuRequested(QPoint)),
this, SLOT(editorCustomContextMenuRequested(QPoint)));
connect(m_d->m_ui.description, SIGNAL(textChanged()),
this, SLOT(updateSubmitAction()));
// File List
m_d->m_ui.fileView->setContextMenuPolicy(Qt::CustomContextMenu);
......@@ -291,11 +293,12 @@ static QString wrappedText(const QTextEdit *e)
QString SubmitEditorWidget::descriptionText() const
{
QString rc = trimMessageText(lineWrap() ? wrappedText(m_d->m_ui.description) : m_d->m_ui.description->toPlainText());
QString rc = trimMessageText(lineWrap() ? wrappedText(m_d->m_ui.description) :
m_d->m_ui.description->toPlainText());
// append field entries
foreach(const SubmitFieldWidget *fw, m_d->m_fieldWidgets)
rc += fw->fieldValues();
return rc;
return cleanupDescription(rc);
}
void SubmitEditorWidget::setDescriptionText(const QString &text)
......@@ -495,6 +498,11 @@ unsigned SubmitEditorWidget::checkedFilesCount() const
return checkedCount;
}
QString SubmitEditorWidget::cleanupDescription(const QString &input) const
{
return input;
}
void SubmitEditorWidget::changeEvent(QEvent *e)
{
QWidget::changeEvent(e);
......
......@@ -139,6 +139,7 @@ public slots:
void uncheckAll();
protected:
virtual QString cleanupDescription(const QString &) const;
virtual void changeEvent(QEvent *e);
void insertTopWidget(QWidget *w);
......
......@@ -120,25 +120,6 @@ void GitSubmitEditor::slotDiffSelected(const QStringList &files)
emit diff(unstagedFiles, stagedFiles);
}
QString GitSubmitEditor::fileContents() const
{
// We need to manually purge out comment lines starting with
// hash '#' since git does not do that when using -F.
const QChar newLine = QLatin1Char('\n');
const QChar hash = QLatin1Char('#');
QString message = VCSBase::VCSBaseSubmitEditor::fileContents();
for (int pos = 0; pos < message.size(); ) {
const int newLinePos = message.indexOf(newLine, pos);
const int startOfNextLine = newLinePos == -1 ? message.size() : newLinePos + 1;
if (message.at(pos) == hash) {
message.remove(pos, startOfNextLine - pos);
} else {
pos = startOfNextLine;
}
}
return message;
}
GitSubmitEditorPanelData GitSubmitEditor::panelData() const
{
return const_cast<GitSubmitEditor*>(this)->submitEditorWidget()->panelData();
......
......@@ -54,8 +54,6 @@ public:
void setCommitData(const CommitData &);
GitSubmitEditorPanelData panelData() const;
virtual QString fileContents() const;
signals:
void diff(const QStringList &unstagedFiles, const QStringList &stagedFiles);
......
......@@ -151,12 +151,35 @@ void GitSubmitEditorWidget::setPanelData(const GitSubmitEditorPanelData &data)
bool GitSubmitEditorWidget::canSubmit() const
{
QString message = cleanupDescription(descriptionText()).trimmed();
if (m_gitSubmitPanelUi.invalidAuthorLabel->isVisible()
|| m_gitSubmitPanelUi.invalidEmailLabel->isVisible())
|| m_gitSubmitPanelUi.invalidEmailLabel->isVisible()
|| message.isEmpty())
return false;
return SubmitEditorWidget::canSubmit();
}
QString GitSubmitEditorWidget::cleanupDescription(const QString &input) const
{
// We need to manually purge out comment lines starting with
// hash '#' since git does not do that when using -F.
const QChar newLine = QLatin1Char('\n');
const QChar hash = QLatin1Char('#');
QString message = input;
for (int pos = 0; pos < message.size(); ) {
const int newLinePos = message.indexOf(newLine, pos);
const int startOfNextLine = newLinePos == -1 ? message.size() : newLinePos + 1;
if (message.at(pos) == hash) {
message.remove(pos, startOfNextLine - pos);
} else {
pos = startOfNextLine;
}
}
return message;
}
void GitSubmitEditorWidget::authorInformationChanged()
{
bool bothEmpty = m_gitSubmitPanelUi.authorLineEdit->text().isEmpty() &&
......
......@@ -67,6 +67,7 @@ public:
protected:
bool canSubmit() const;
QString cleanupDescription(const QString &) const;
private slots:
void authorInformationChanged();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment