forked from qt-creator/qt-creator
Git: Added soft Reset
Added Soft Reset to Reset Dialog Change-Id: Iba5b6a37aef2b89c998c21a3d8ecca1075cbda10 Reviewed-by: Orgad Shaneh <orgads@gmail.com> Reviewed-by: Tobias Hunger <tobias.hunger@digia.com>
This commit is contained in:
committed by
Tobias Hunger
parent
c002c598b9
commit
3afa4a199f
@@ -835,6 +835,18 @@ void GitClient::hardReset(const QString &workingDirectory, const QString &commit
|
||||
connectRepositoryChanged(workingDirectory, cmd);
|
||||
}
|
||||
|
||||
void GitClient::softReset(const QString &workingDirectory, const QString &commit)
|
||||
{
|
||||
if (commit.isEmpty())
|
||||
return;
|
||||
|
||||
QStringList arguments;
|
||||
arguments << QLatin1String("reset") << QLatin1String("--soft") << commit;
|
||||
|
||||
VcsBase::Command *cmd = executeGit(workingDirectory, arguments, 0, true);
|
||||
connectRepositoryChanged(workingDirectory, cmd);
|
||||
}
|
||||
|
||||
void GitClient::addFile(const QString &workingDirectory, const QString &fileName)
|
||||
{
|
||||
QStringList arguments;
|
||||
|
||||
@@ -111,6 +111,7 @@ public:
|
||||
void checkout(const QString &workingDirectory, const QString &file);
|
||||
void checkoutBranch(const QString &workingDirectory, const QString &branch);
|
||||
void hardReset(const QString &workingDirectory, const QString &commit = QString());
|
||||
void softReset(const QString &workingDirectory, const QString &commit);
|
||||
void addFile(const QString &workingDirectory, const QString &fileName);
|
||||
bool synchronousLog(const QString &workingDirectory,
|
||||
const QStringList &arguments,
|
||||
|
||||
@@ -694,7 +694,14 @@ void GitPlugin::resetRepository()
|
||||
|
||||
ResetDialog dialog;
|
||||
if (dialog.runDialog(state.topLevel()))
|
||||
m_gitClient->hardReset(state.topLevel(), dialog.commit());
|
||||
switch (dialog.resetType()) {
|
||||
case HardReset:
|
||||
m_gitClient->hardReset(state.topLevel(), dialog.commit());
|
||||
break;
|
||||
case SoftReset:
|
||||
m_gitClient->softReset(state.topLevel(), dialog.commit());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void GitPlugin::stageFile()
|
||||
|
||||
@@ -33,11 +33,12 @@
|
||||
|
||||
#include <QTreeView>
|
||||
#include <QLabel>
|
||||
#include <QDialogButtonBox>
|
||||
#include <QPushButton>
|
||||
#include <QStandardItemModel>
|
||||
#include <QDialogButtonBox>
|
||||
#include <QItemSelectionModel>
|
||||
#include <QVBoxLayout>
|
||||
#include <QComboBox>
|
||||
#include <QDir>
|
||||
|
||||
namespace Git {
|
||||
@@ -55,21 +56,31 @@ ResetDialog::ResetDialog(QWidget *parent)
|
||||
, m_treeView(new QTreeView(this))
|
||||
, m_model(new QStandardItemModel(0, ColumnCount, this))
|
||||
, m_dialogButtonBox(new QDialogButtonBox(this))
|
||||
, m_resetTypeComboBox(new QComboBox(this))
|
||||
{
|
||||
QStringList headers;
|
||||
headers << tr("Sha1")<< tr("Subject");
|
||||
m_model->setHorizontalHeaderLabels(headers);
|
||||
QVBoxLayout *layout = new QVBoxLayout(this);
|
||||
layout->addWidget(new QLabel(tr("Reset to:")));
|
||||
layout->addWidget(new QLabel(tr("Reset to:"), this));
|
||||
m_treeView->setModel(m_model);
|
||||
m_treeView->setMinimumWidth(300);
|
||||
m_treeView->setUniformRowHeights(true);
|
||||
m_treeView->setRootIsDecorated(false);
|
||||
m_treeView->setSelectionBehavior(QAbstractItemView::SelectRows);
|
||||
layout->addWidget(m_treeView);
|
||||
layout->addWidget(m_dialogButtonBox);
|
||||
QHBoxLayout *popUpLayout = new QHBoxLayout();
|
||||
popUpLayout->addWidget(new QLabel(tr("Reset type:"), this));
|
||||
m_resetTypeComboBox->addItem(tr("Hard Reset"), HardReset);
|
||||
m_resetTypeComboBox->addItem(tr("Soft Reset"), SoftReset);
|
||||
popUpLayout->addWidget(m_resetTypeComboBox);
|
||||
popUpLayout->addItem(new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Ignored));
|
||||
|
||||
popUpLayout->addWidget(m_dialogButtonBox);
|
||||
m_dialogButtonBox->addButton(QDialogButtonBox::Cancel);
|
||||
QPushButton *okButton = m_dialogButtonBox->addButton(QDialogButtonBox::Ok);
|
||||
layout->addLayout(popUpLayout);
|
||||
|
||||
connect(m_treeView, SIGNAL(doubleClicked(QModelIndex)),
|
||||
okButton, SLOT(animateClick()));
|
||||
|
||||
@@ -101,6 +112,11 @@ QString ResetDialog::commit() const
|
||||
return QString();
|
||||
}
|
||||
|
||||
ResetType ResetDialog::resetType() const
|
||||
{
|
||||
return static_cast<ResetType>(m_resetTypeComboBox->itemData(m_resetTypeComboBox->currentIndex()).toInt());
|
||||
}
|
||||
|
||||
bool ResetDialog::populateLog(const QString &repository)
|
||||
{
|
||||
if (const int rowCount = m_model->rowCount())
|
||||
|
||||
@@ -35,6 +35,7 @@
|
||||
QT_BEGIN_NAMESPACE
|
||||
class QTreeView;
|
||||
class QDialogButtonBox;
|
||||
class QComboBox;
|
||||
class QStandardItemModel;
|
||||
class QStandardItem;
|
||||
QT_END_NAMESPACE
|
||||
@@ -43,7 +44,12 @@ namespace Git {
|
||||
namespace Internal {
|
||||
|
||||
// A dialog that lists SHA1 and subject of the changes
|
||||
// for reset --hard.
|
||||
// for reset --hard and --soft.
|
||||
|
||||
enum ResetType {
|
||||
HardReset,
|
||||
SoftReset
|
||||
};
|
||||
|
||||
class ResetDialog : public QDialog
|
||||
{
|
||||
@@ -54,6 +60,7 @@ public:
|
||||
bool runDialog(const QString &repository);
|
||||
|
||||
QString commit() const;
|
||||
ResetType resetType() const;
|
||||
|
||||
private:
|
||||
bool populateLog(const QString &repository);
|
||||
@@ -62,6 +69,7 @@ private:
|
||||
QTreeView *m_treeView;
|
||||
QStandardItemModel *m_model;
|
||||
QDialogButtonBox *m_dialogButtonBox;
|
||||
QComboBox *m_resetTypeComboBox;
|
||||
};
|
||||
|
||||
} // namespace Internal
|
||||
|
||||
Reference in New Issue
Block a user