diff options
author | Petar Perisin <petar.perisin@gmail.com> | 2014-01-14 19:58:46 +0100 |
---|---|---|
committer | Petar Perisin <petar.perisin@gmail.com> | 2014-01-16 00:54:22 +0100 |
commit | f23922f84a16f1c469014a5763729a6f40c5fac0 (patch) | |
tree | 98884b74e655be14e89075fd86387ff6b94c64fa /src/plugins/git/giteditor.cpp | |
parent | b245bfc65d56bf05f659aa3f7c7e928c58ca4382 (diff) | |
download | qt-creator-f23922f84a16f1c469014a5763729a6f40c5fac0.tar.gz |
Git: Added ability to checkout and reset in GitEditor
Especially useful in reflog.
Change-Id: I1d63221f152ebc7e69934482785b433d016e4ead
Reviewed-by: Tobias Hunger <tobias.hunger@digia.com>
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
Reviewed-by: Petar Perisin <petar.perisin@gmail.com>
Diffstat (limited to 'src/plugins/git/giteditor.cpp')
-rw-r--r-- | src/plugins/git/giteditor.cpp | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/plugins/git/giteditor.cpp b/src/plugins/git/giteditor.cpp index c21b6166dd..8e979d8208 100644 --- a/src/plugins/git/giteditor.cpp +++ b/src/plugins/git/giteditor.cpp @@ -37,6 +37,7 @@ #include "gitconstants.h" #include "githighlighters.h" +#include <coreplugin/icore.h> #include <utils/qtcassert.h> #include <vcsbase/vcsbaseoutputwindow.h> #include <texteditor/basetextdocument.h> @@ -212,6 +213,32 @@ void GitEditor::commandFinishedGotoLine(bool ok, int exitCode, const QVariant &v } } +void GitEditor::checkoutChange() +{ + const QFileInfo fi(source()); + const QString workingDirectory = fi.isDir() ? fi.absoluteFilePath() : fi.absolutePath(); + GitPlugin::instance()->gitClient()->stashAndCheckout(workingDirectory, m_currentChange); +} + +void GitEditor::resetChange() +{ + const QFileInfo fi(source()); + const QString workingDir = fi.isDir() ? fi.absoluteFilePath() : fi.absolutePath(); + + GitClient *client = GitPlugin::instance()->gitClient(); + if (client->gitStatus(workingDir, StatusMode(NoUntracked | NoSubmodules)) + != GitClient::StatusUnchanged) { + if (QMessageBox::question( + Core::ICore::mainWindow(), tr("Reset"), + tr("All changes in working directory will be discarded. Are you sure?"), + QMessageBox::Yes | QMessageBox::No, + QMessageBox::No) == QMessageBox::No) { + return; + } + } + client->reset(workingDir, QLatin1String("--hard"), m_currentChange); +} + void GitEditor::cherryPickChange() { const QFileInfo fi(source()); @@ -344,6 +371,8 @@ void GitEditor::addChangeActions(QMenu *menu, const QString &change) if (contentType() != VcsBase::OtherContent) { menu->addAction(tr("Cherry-Pick Change %1").arg(change), this, SLOT(cherryPickChange())); menu->addAction(tr("Revert Change %1").arg(change), this, SLOT(revertChange())); + menu->addAction(tr("Checkout Change %1").arg(change), this, SLOT(checkoutChange())); + menu->addAction(tr("Hard Reset to Change %1").arg(change), this, SLOT(resetChange())); } } |