Commit 06da25f6 authored by Orgad Shaneh's avatar Orgad Shaneh Committed by Orgad Shaneh
Browse files

Git: Add commit type to CommitData



Change-Id: I900f3dd89eeeac61e29604ac459d36ecc6c0aa8f
Reviewed-by: default avatarTobias Hunger <tobias.hunger@digia.com>
parent cb055c1d
......@@ -76,6 +76,10 @@ QDebug operator<<(QDebug d, const GitSubmitEditorPanelData &data)
return d;
}
CommitData::CommitData(CommitType type) : commitType(type)
{
}
void CommitData::clear()
{
panelInfo.clear();
......
......@@ -30,6 +30,8 @@
#ifndef COMMITDATA_H
#define COMMITDATA_H
#include "gitsettings.h" // CommitType
#include <QStringList>
#include <QPair>
......@@ -85,6 +87,7 @@ Q_DECLARE_FLAGS(FileStates, FileState)
class CommitData
{
public:
CommitData(CommitType type = SimpleCommit);
// A pair of state string/file name ('modified', 'file.cpp').
typedef QPair<FileStates, QString> StateFilePair;
......@@ -99,6 +102,7 @@ public:
static QString stateDisplayName(const FileStates &state);
CommitType commitType;
QString amendSHA1;
QString commitEncoding;
GitSubmitEditorPanelInfo panelInfo;
......
......@@ -2018,7 +2018,6 @@ QString GitClient::gitBinaryPath(bool *ok, QString *errorMessage) const
}
bool GitClient::getCommitData(const QString &workingDirectory,
CommitType commitType,
QString *commitTemplate,
CommitData *commitData,
QString *errorMessage)
......@@ -2047,7 +2046,7 @@ bool GitClient::getCommitData(const QString &workingDirectory,
case StatusChanged:
break;
case StatusUnchanged:
if (commitType == AmendCommit)
if (commitData->commitType == AmendCommit) // amend might be run just for the commit message
break;
*errorMessage = msgNoChangedFiles();
return false;
......@@ -2081,7 +2080,7 @@ bool GitClient::getCommitData(const QString &workingDirectory,
}
commitData->files = filteredFiles;
if (commitData->files.isEmpty() && commitType != AmendCommit) {
if (commitData->files.isEmpty() && commitData->commitType != AmendCommit) {
*errorMessage = msgNoChangedFiles();
return false;
}
......@@ -2090,7 +2089,7 @@ bool GitClient::getCommitData(const QString &workingDirectory,
commitData->commitEncoding = readConfigValue(workingDirectory, QLatin1String("i18n.commitEncoding"));
// Get the commit template or the last commit message
switch (commitType) {
switch (commitData->commitType) {
case AmendCommit: {
// Amend: get last commit data as "SHA1<tab>author<tab>email<tab>message".
QStringList args(QLatin1String("log"));
......
......@@ -261,9 +261,8 @@ public:
QString readConfigValue(const QString &workingDirectory, const QString &configVar) const;
bool getCommitData(const QString &workingDirectory, CommitType commitType,
QString *commitTemplate, CommitData *commitData,
QString *errorMessage);
bool getCommitData(const QString &workingDirectory, QString *commitTemplate,
CommitData *commitData, QString *errorMessage);
bool addAndCommit(const QString &workingDirectory,
const GitSubmitEditorPanelData &data,
......
......@@ -896,8 +896,8 @@ void GitPlugin::startCommit(CommitType commitType)
QTC_ASSERT(state.hasTopLevel(), return);
QString errorMessage, commitTemplate;
CommitData data;
if (!m_gitClient->getCommitData(state.topLevel(), commitType, &commitTemplate, &data, &errorMessage)) {
CommitData data(commitType);
if (!m_gitClient->getCommitData(state.topLevel(), &commitTemplate, &data, &errorMessage)) {
VcsBase::VcsBaseOutputWindow::instance()->append(errorMessage);
return;
}
......@@ -917,7 +917,7 @@ void GitPlugin::startCommit(CommitType commitType)
return;
}
m_commitMessageFileName = saver.fileName();
openSubmitEditor(m_commitMessageFileName, data, commitType);
openSubmitEditor(m_commitMessageFileName, data);
}
void GitPlugin::updateVersionWarning()
......@@ -940,7 +940,7 @@ void GitPlugin::updateVersionWarning()
Core::InfoBarEntry::GlobalSuppressionEnabled));
}
Core::IEditor *GitPlugin::openSubmitEditor(const QString &fileName, const CommitData &cd, CommitType commitType)
Core::IEditor *GitPlugin::openSubmitEditor(const QString &fileName, const CommitData &cd)
{
Core::IEditor *editor = Core::EditorManager::openEditor(fileName, Constants::GITSUBMITEDITOR_ID,
Core::EditorManager::ModeSwitch);
......@@ -952,9 +952,8 @@ 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 = (commitType == AmendCommit) ? tr("Amend %1").arg(cd.amendSHA1) : tr("Git Commit");
const QString title = (cd.commitType == AmendCommit) ? tr("Amend %1").arg(cd.amendSHA1) : tr("Git Commit");
submitEditor->setDisplayName(title);
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,7 +192,7 @@ private:
void updateContinueAndAbortCommands();
void updateRepositoryBrowserAction();
bool isCommitEditorOpen() const;
Core::IEditor *openSubmitEditor(const QString &fileName, const CommitData &cd, CommitType commitType);
Core::IEditor *openSubmitEditor(const QString &fileName, const CommitData &cd);
void cleanCommitMessageFile();
void cleanRepository(const QString &directory);
void applyPatch(const QString &workingDirectory, QString file = QString());
......
......@@ -110,6 +110,8 @@ void GitSubmitEditor::setCommitData(const CommitData &d)
m_commitEncoding = d.commitEncoding;
m_workingDirectory = d.panelInfo.repository;
m_commitType = d.commitType;
setEmptyFileListEnabled(m_commitType == AmendCommit); // Allow for just correcting the message
m_model = new GitSubmitFileModel(this);
if (!d.files.isEmpty()) {
......@@ -133,12 +135,6 @@ void GitSubmitEditor::setCommitData(const CommitData &d)
setFileModel(m_model, d.panelInfo.repository);
}
void GitSubmitEditor::setCommitType(CommitType commitType)
{
m_commitType = commitType;
setEmptyFileListEnabled(commitType == AmendCommit); // Allow for just correcting the message
}
void GitSubmitEditor::slotDiffSelected(const QList<int> &rows)
{
// Sort it apart into unmerged/staged/unstaged files
......@@ -167,8 +163,8 @@ void GitSubmitEditor::updateFileModel()
return;
GitClient *client = GitPlugin::instance()->gitClient();
QString errorMessage, commitTemplate;
CommitData data;
if (client->getCommitData(m_workingDirectory, m_commitType, &commitTemplate, &data, &errorMessage)) {
CommitData data(m_commitType);
if (client->getCommitData(m_workingDirectory, &commitTemplate, &data, &errorMessage)) {
setCommitData(data);
} else {
VcsBase::VcsBaseOutputWindow::instance()->append(errorMessage);
......
......@@ -54,7 +54,6 @@ public:
explicit GitSubmitEditor(const VcsBase::VcsBaseSubmitEditorParameters *parameters, QWidget *parent);
void setCommitData(const CommitData &);
void setCommitType(CommitType commitType);
GitSubmitEditorPanelData panelData() const;
bool forceClose() const { return m_forceClose; }
......
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