forked from qt-creator/qt-creator
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>
This commit is contained in:
@@ -37,6 +37,7 @@
|
|||||||
#include "gitconstants.h"
|
#include "gitconstants.h"
|
||||||
#include "githighlighters.h"
|
#include "githighlighters.h"
|
||||||
|
|
||||||
|
#include <coreplugin/icore.h>
|
||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
#include <vcsbase/vcsbaseoutputwindow.h>
|
#include <vcsbase/vcsbaseoutputwindow.h>
|
||||||
#include <texteditor/basetextdocument.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()
|
void GitEditor::cherryPickChange()
|
||||||
{
|
{
|
||||||
const QFileInfo fi(source());
|
const QFileInfo fi(source());
|
||||||
@@ -344,6 +371,8 @@ void GitEditor::addChangeActions(QMenu *menu, const QString &change)
|
|||||||
if (contentType() != VcsBase::OtherContent) {
|
if (contentType() != VcsBase::OtherContent) {
|
||||||
menu->addAction(tr("Cherry-Pick Change %1").arg(change), this, SLOT(cherryPickChange()));
|
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("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()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -55,6 +55,8 @@ public slots:
|
|||||||
void commandFinishedGotoLine(bool ok, int exitCode, const QVariant &v);
|
void commandFinishedGotoLine(bool ok, int exitCode, const QVariant &v);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
|
void checkoutChange();
|
||||||
|
void resetChange();
|
||||||
void cherryPickChange();
|
void cherryPickChange();
|
||||||
void revertChange();
|
void revertChange();
|
||||||
void stageDiffChunk();
|
void stageDiffChunk();
|
||||||
|
|||||||
Reference in New Issue
Block a user