diff --git a/src/plugins/git/gitclient.cpp b/src/plugins/git/gitclient.cpp index 8b62ecec1255364a075469215e74773d78cce330..028b62bdf3830b3b1559465e96ebcad262e43d15 100644 --- a/src/plugins/git/gitclient.cpp +++ b/src/plugins/git/gitclient.cpp @@ -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; diff --git a/src/plugins/git/gitclient.h b/src/plugins/git/gitclient.h index 8482febc92bee9384ae8c3768a71ea0339e7d29f..cd24f28ee304e90225014fa3fc98f157b12546a1 100644 --- a/src/plugins/git/gitclient.h +++ b/src/plugins/git/gitclient.h @@ -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, diff --git a/src/plugins/git/gitplugin.cpp b/src/plugins/git/gitplugin.cpp index 1027ddfb3966ec14708ab7fcbe358ed3a59573de..1081bf3cdf619b04e0ddd938a48fa7e17ac7dbed 100644 --- a/src/plugins/git/gitplugin.cpp +++ b/src/plugins/git/gitplugin.cpp @@ -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() diff --git a/src/plugins/git/resetdialog.cpp b/src/plugins/git/resetdialog.cpp index eeecdb0dc922be5a16780ead7b47a7e49983b834..580f95bd71982f72691473e8d0a9d128fa5efa72 100644 --- a/src/plugins/git/resetdialog.cpp +++ b/src/plugins/git/resetdialog.cpp @@ -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()) diff --git a/src/plugins/git/resetdialog.h b/src/plugins/git/resetdialog.h index 377f9b06e84b373ae68b0f9446a953998516633d..ea77e4d7f21b91306ca63f4ecb799417f306f691 100644 --- a/src/plugins/git/resetdialog.h +++ b/src/plugins/git/resetdialog.h @@ -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