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
This commit is contained in:
Tobias Hunger
2010-11-23 16:00:33 +01:00
parent 2f07660e5b
commit d1976d1959
6 changed files with 36 additions and 24 deletions

View File

@@ -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();

View File

@@ -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);

View File

@@ -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() &&

View File

@@ -67,6 +67,7 @@ public:
protected:
bool canSubmit() const;
QString cleanupDescription(const QString &) const;
private slots:
void authorInformationChanged();