Commit 83997d0e authored by Waqar Ahmed's avatar Waqar Ahmed
Browse files

Allow signing-off commit messages using commit dialog


Signed-off-by: Waqar Ahmed's avatarWaqar Ahmed <waqar.17a@gmail.com>
parent 0222a815
......@@ -111,6 +111,10 @@ GitCommitDialog::GitCommitDialog(const QString &lastCommit, const QFont &font, Q
}
}
m_cbSignOff.setChecked(false);
m_cbSignOff.setText(i18n("Sign off"));
vlayout->addWidget(&m_cbSignOff);
QHBoxLayout *hLayout = new QHBoxLayout;
hLayout->addStretch();
hLayout->addWidget(&ok);
......@@ -121,9 +125,6 @@ GitCommitDialog::GitCommitDialog(const QString &lastCommit, const QFont &font, Q
connect(m_le, &QPlainTextEdit::textChanged, this, &GitCommitDialog::updateLineSizeLabel);
updateLineSizeLabel();
// m_cbSeventyTwoLimit.setText(i18n("Automatically break description into 72 or less character lines"));
// m_cbSeventyTwoLimit.setChecked(true);
// vlayout->addWidget(&m_cbSeventyTwoLimit);
vlayout->addLayout(hLayout);
}
......@@ -138,6 +139,11 @@ QString GitCommitDialog::description() const
return m_pe.toPlainText();
}
bool GitCommitDialog::signoff() const
{
return m_cbSignOff.isChecked();
}
void GitCommitDialog::updateLineSizeLabel()
{
int len = m_le->textLength();
......
#ifndef GITCOMMITDIALOG_H
/*
SPDX-FileCopyrightText: 2021 Waqar Ahmed <waqar.17a@gmail.com>
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#ifndef GITCOMMITDIALOG_H
#define GITCOMMITDIALOG_H
#include <QCheckBox>
#include <QDialog>
#include <QLabel>
#include <QLineEdit>
#include <QPlainTextEdit>
#include <QPushButton>
#include <memory>
class SingleLineEdit;
class BadLengthHighlighter;
......@@ -27,6 +26,7 @@ public:
QString subject() const;
QString description() const;
bool signoff() const;
private:
Q_SLOT void updateLineSizeLabel();
......@@ -37,6 +37,7 @@ private:
QPushButton cancel;
QLabel m_leLen;
QLabel m_peLen;
QCheckBox m_cbSignOff;
BadLengthHighlighter *m_hl;
};
......
......@@ -328,9 +328,14 @@ void GitWidget::launchExternalDiffTool(const QString &file, bool staged)
git.start();
}
void GitWidget::commitChanges(const QString &msg, const QString &desc)
void GitWidget::commitChanges(const QString &msg, const QString &desc, bool signOff)
{
auto args = QStringList{QStringLiteral("commit"), QStringLiteral("-m"), msg};
auto args = QStringList{QStringLiteral("commit")};
if (signOff) {
args.append(QStringLiteral("-s"));
}
args.append(QStringLiteral("-m"));
args.append(msg);
if (!desc.isEmpty()) {
args.append(QStringLiteral("-m"));
args.append(desc);
......@@ -347,6 +352,7 @@ void GitWidget::commitChanges(const QString &msg, const QString &desc)
sendMessage(i18n("Failed to commit. \n %1", QString::fromUtf8(git.readAllStandardError())), true);
} else {
sendMessage(i18n("Changes committed successfully."), false);
m_commitMessage.clear();
// refresh
getStatus();
}
......@@ -375,9 +381,8 @@ void GitWidget::opencommitChangesDialog()
if (dialog.subject().isEmpty()) {
return sendMessage(i18n("Commit message cannot be empty."), true);
}
commitChanges(dialog.subject(), dialog.description());
} else {
m_commitMessage = dialog.subject() + QStringLiteral("[[\n\n]]") + dialog.description();
commitChanges(dialog.subject(), dialog.description(), dialog.signoff());
}
}
......
......@@ -64,7 +64,7 @@ private:
void openAtHEAD(const QString &file);
void showDiff(const QString &file, bool staged);
void launchExternalDiffTool(const QString &file, bool staged);
void commitChanges(const QString &msg, const QString &desc);
void commitChanges(const QString &msg, const QString &desc, bool signOff);
void sendMessage(const QString &message, bool warn);
void hideEmptyTreeNodes();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment