forked from qt-creator/qt-creator
Git: Use an enum for simple/amend commit
Change-Id: Ibea0a1f2826c67796a56414326fe6afdee654576 Reviewed-by: Tobias Hunger <tobias.hunger@digia.com>
This commit is contained in:
committed by
Orgad Shaneh
parent
2b41210b3f
commit
7b851602cc
@@ -2018,7 +2018,7 @@ QString GitClient::gitBinaryPath(bool *ok, QString *errorMessage) const
|
||||
}
|
||||
|
||||
bool GitClient::getCommitData(const QString &workingDirectory,
|
||||
bool amend,
|
||||
CommitType commitType,
|
||||
QString *commitTemplate,
|
||||
CommitData *commitData,
|
||||
QString *errorMessage)
|
||||
@@ -2047,7 +2047,7 @@ bool GitClient::getCommitData(const QString &workingDirectory,
|
||||
case StatusChanged:
|
||||
break;
|
||||
case StatusUnchanged:
|
||||
if (amend)
|
||||
if (commitType == AmendCommit)
|
||||
break;
|
||||
*errorMessage = msgNoChangedFiles();
|
||||
return false;
|
||||
@@ -2081,7 +2081,7 @@ bool GitClient::getCommitData(const QString &workingDirectory,
|
||||
}
|
||||
commitData->files = filteredFiles;
|
||||
|
||||
if (commitData->files.isEmpty() && !amend) {
|
||||
if (commitData->files.isEmpty() && commitType != AmendCommit) {
|
||||
*errorMessage = msgNoChangedFiles();
|
||||
return false;
|
||||
}
|
||||
@@ -2090,7 +2090,8 @@ bool GitClient::getCommitData(const QString &workingDirectory,
|
||||
commitData->commitEncoding = readConfigValue(workingDirectory, QLatin1String("i18n.commitEncoding"));
|
||||
|
||||
// Get the commit template or the last commit message
|
||||
if (amend) {
|
||||
switch (commitType) {
|
||||
case AmendCommit: {
|
||||
// Amend: get last commit data as "SHA1<tab>author<tab>email<tab>message".
|
||||
QStringList args(QLatin1String("log"));
|
||||
args << QLatin1String("--max-count=1") << QLatin1String("--pretty=format:%h\t%an\t%ae\t%B");
|
||||
@@ -2106,7 +2107,9 @@ bool GitClient::getCommitData(const QString &workingDirectory,
|
||||
commitData->panelData.author = values.takeFirst();
|
||||
commitData->panelData.email = values.takeFirst();
|
||||
*commitTemplate = values.join(QLatin1String("\t"));
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
case SimpleCommit: {
|
||||
commitData->panelData.author = readConfigValue(workingDirectory, QLatin1String("user.name"));
|
||||
commitData->panelData.email = readConfigValue(workingDirectory, QLatin1String("user.email"));
|
||||
// Commit: Get the commit template
|
||||
@@ -2126,6 +2129,8 @@ bool GitClient::getCommitData(const QString &workingDirectory,
|
||||
return false;
|
||||
*commitTemplate = QString::fromLocal8Bit(reader.data());
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -261,7 +261,7 @@ public:
|
||||
|
||||
QString readConfigValue(const QString &workingDirectory, const QString &configVar) const;
|
||||
|
||||
bool getCommitData(const QString &workingDirectory, bool amend,
|
||||
bool getCommitData(const QString &workingDirectory, CommitType commitType,
|
||||
QString *commitTemplate, CommitData *commitData,
|
||||
QString *errorMessage);
|
||||
|
||||
|
||||
@@ -875,15 +875,15 @@ void GitPlugin::gitkForCurrentFolder()
|
||||
|
||||
void GitPlugin::startAmendCommit()
|
||||
{
|
||||
startCommit(true);
|
||||
startCommit(AmendCommit);
|
||||
}
|
||||
|
||||
void GitPlugin::startCommit()
|
||||
{
|
||||
startCommit(false);
|
||||
startCommit(SimpleCommit);
|
||||
}
|
||||
|
||||
void GitPlugin::startCommit(bool amend)
|
||||
void GitPlugin::startCommit(CommitType commitType)
|
||||
{
|
||||
if (raiseSubmitEditor())
|
||||
return;
|
||||
@@ -897,7 +897,7 @@ void GitPlugin::startCommit(bool amend)
|
||||
|
||||
QString errorMessage, commitTemplate;
|
||||
CommitData data;
|
||||
if (!m_gitClient->getCommitData(state.topLevel(), amend, &commitTemplate, &data, &errorMessage)) {
|
||||
if (!m_gitClient->getCommitData(state.topLevel(), commitType, &commitTemplate, &data, &errorMessage)) {
|
||||
VcsBase::VcsBaseOutputWindow::instance()->append(errorMessage);
|
||||
return;
|
||||
}
|
||||
@@ -917,7 +917,7 @@ void GitPlugin::startCommit(bool amend)
|
||||
return;
|
||||
}
|
||||
m_commitMessageFileName = saver.fileName();
|
||||
openSubmitEditor(m_commitMessageFileName, data, amend);
|
||||
openSubmitEditor(m_commitMessageFileName, data, commitType);
|
||||
}
|
||||
|
||||
void GitPlugin::updateVersionWarning()
|
||||
@@ -940,7 +940,7 @@ void GitPlugin::updateVersionWarning()
|
||||
Core::InfoBarEntry::GlobalSuppressionEnabled));
|
||||
}
|
||||
|
||||
Core::IEditor *GitPlugin::openSubmitEditor(const QString &fileName, const CommitData &cd, bool amend)
|
||||
Core::IEditor *GitPlugin::openSubmitEditor(const QString &fileName, const CommitData &cd, CommitType commitType)
|
||||
{
|
||||
Core::IEditor *editor = Core::EditorManager::openEditor(fileName, Constants::GITSUBMITEDITOR_ID,
|
||||
Core::EditorManager::ModeSwitch);
|
||||
@@ -952,9 +952,9 @@ Core::IEditor *GitPlugin::openSubmitEditor(const QString &fileName, const Commit
|
||||
submitEditor->registerActions(m_undoAction, m_redoAction, m_submitCurrentAction, m_diffSelectedFilesAction);
|
||||
submitEditor->setCommitData(cd);
|
||||
submitEditor->setCheckScriptWorkingDirectory(m_submitRepository);
|
||||
const QString title = amend ? tr("Amend %1").arg(cd.amendSHA1) : tr("Git Commit");
|
||||
const QString title = (commitType == AmendCommit) ? tr("Amend %1").arg(cd.amendSHA1) : tr("Git Commit");
|
||||
submitEditor->setDisplayName(title);
|
||||
submitEditor->setAmend(amend);
|
||||
submitEditor->setCommitType(commitType);
|
||||
connect(submitEditor, SIGNAL(diff(QStringList,QStringList)), this, SLOT(submitEditorDiff(QStringList,QStringList)));
|
||||
connect(submitEditor, SIGNAL(merge(QStringList)), this, SLOT(submitEditorMerge(QStringList)));
|
||||
return editor;
|
||||
|
||||
@@ -192,11 +192,11 @@ private:
|
||||
void updateContinueAndAbortCommands();
|
||||
void updateRepositoryBrowserAction();
|
||||
bool isCommitEditorOpen() const;
|
||||
Core::IEditor *openSubmitEditor(const QString &fileName, const CommitData &cd, bool amend);
|
||||
Core::IEditor *openSubmitEditor(const QString &fileName, const CommitData &cd, CommitType commitType);
|
||||
void cleanCommitMessageFile();
|
||||
void cleanRepository(const QString &directory);
|
||||
void applyPatch(const QString &workingDirectory, QString file = QString());
|
||||
void startCommit(bool amend);
|
||||
void startCommit(CommitType commitType);
|
||||
void updateVersionWarning();
|
||||
|
||||
static GitPlugin *m_instance;
|
||||
|
||||
@@ -35,6 +35,12 @@
|
||||
namespace Git {
|
||||
namespace Internal {
|
||||
|
||||
enum CommitType
|
||||
{
|
||||
SimpleCommit,
|
||||
AmendCommit
|
||||
};
|
||||
|
||||
// Todo: Add user name and password?
|
||||
class GitSettings : public VcsBase::VcsBaseClientSettings
|
||||
{
|
||||
|
||||
@@ -85,7 +85,7 @@ private:
|
||||
GitSubmitEditor::GitSubmitEditor(const VcsBase::VcsBaseSubmitEditorParameters *parameters, QWidget *parent) :
|
||||
VcsBaseSubmitEditor(parameters, new GitSubmitEditorWidget(parent)),
|
||||
m_model(0),
|
||||
m_amend(false),
|
||||
m_commitType(SimpleCommit),
|
||||
m_forceClose(false)
|
||||
{
|
||||
connect(this, SIGNAL(diffSelectedFiles(QList<int>)), this, SLOT(slotDiffSelected(QList<int>)));
|
||||
@@ -128,10 +128,10 @@ void GitSubmitEditor::setCommitData(const CommitData &d)
|
||||
setFileModel(m_model, d.panelInfo.repository);
|
||||
}
|
||||
|
||||
void GitSubmitEditor::setAmend(bool amend)
|
||||
void GitSubmitEditor::setCommitType(CommitType commitType)
|
||||
{
|
||||
m_amend = amend;
|
||||
setEmptyFileListEnabled(amend); // Allow for just correcting the message
|
||||
m_commitType = commitType;
|
||||
setEmptyFileListEnabled(commitType == AmendCommit); // Allow for just correcting the message
|
||||
}
|
||||
|
||||
void GitSubmitEditor::slotDiffSelected(const QList<int> &rows)
|
||||
@@ -163,7 +163,7 @@ void GitSubmitEditor::updateFileModel()
|
||||
GitClient *client = GitPlugin::instance()->gitClient();
|
||||
QString errorMessage, commitTemplate;
|
||||
CommitData data;
|
||||
if (client->getCommitData(m_workingDirectory, m_amend, &commitTemplate, &data, &errorMessage)) {
|
||||
if (client->getCommitData(m_workingDirectory, m_commitType, &commitTemplate, &data, &errorMessage)) {
|
||||
setCommitData(data);
|
||||
} else {
|
||||
VcsBase::VcsBaseOutputWindow::instance()->append(errorMessage);
|
||||
|
||||
@@ -30,6 +30,8 @@
|
||||
#ifndef GITSUBMITEDITOR_H
|
||||
#define GITSUBMITEDITOR_H
|
||||
|
||||
#include "gitsettings.h" // CommitType
|
||||
|
||||
#include <vcsbase/vcsbasesubmiteditor.h>
|
||||
|
||||
#include <QStringList>
|
||||
@@ -52,7 +54,7 @@ public:
|
||||
explicit GitSubmitEditor(const VcsBase::VcsBaseSubmitEditorParameters *parameters, QWidget *parent);
|
||||
|
||||
void setCommitData(const CommitData &);
|
||||
void setAmend(bool amend);
|
||||
void setCommitType(CommitType commitType);
|
||||
GitSubmitEditorPanelData panelData() const;
|
||||
bool forceClose() const { return m_forceClose; }
|
||||
|
||||
@@ -72,7 +74,7 @@ private:
|
||||
|
||||
VcsBase::SubmitFileModel *m_model;
|
||||
QString m_commitEncoding;
|
||||
bool m_amend;
|
||||
CommitType m_commitType;
|
||||
bool m_forceClose;
|
||||
QString m_workingDirectory;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user