aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPetar Perisin <[email protected]>2013-01-03 21:37:50 +0100
committerTobias Hunger <[email protected]>2013-01-09 13:26:35 +0100
commit3afa4a199fdc82a4183ff7164bdd4310c8898120 (patch)
treea1c77c5d5d8aa55437f678b2789b8c446b00019d
parentc002c598b9bd41651436d85f9322931ada235f9a (diff)
Git: Added soft Reset
Added Soft Reset to Reset Dialog Change-Id: Iba5b6a37aef2b89c998c21a3d8ecca1075cbda10 Reviewed-by: Orgad Shaneh <[email protected]> Reviewed-by: Tobias Hunger <[email protected]>
-rw-r--r--src/plugins/git/gitclient.cpp12
-rw-r--r--src/plugins/git/gitclient.h1
-rw-r--r--src/plugins/git/gitplugin.cpp9
-rw-r--r--src/plugins/git/resetdialog.cpp22
-rw-r--r--src/plugins/git/resetdialog.h10
5 files changed, 49 insertions, 5 deletions
diff --git a/src/plugins/git/gitclient.cpp b/src/plugins/git/gitclient.cpp
index 8b62ecec125..028b62bdf38 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 8482febc92b..cd24f28ee30 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 1027ddfb396..1081bf3cdf6 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 eeecdb0dc92..580f95bd719 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 377f9b06e84..ea77e4d7f21 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