Skip to content
Snippets Groups Projects
Commit f23922f8 authored by Petar Perisin's avatar Petar Perisin
Browse files

Git: Added ability to checkout and reset in GitEditor


Especially useful in reflog.

Change-Id: I1d63221f152ebc7e69934482785b433d016e4ead
Reviewed-by: default avatarTobias Hunger <tobias.hunger@digia.com>
Reviewed-by: default avatarOrgad Shaneh <orgads@gmail.com>
Reviewed-by: default avatarPetar Perisin <petar.perisin@gmail.com>
parent b245bfc6
No related branches found
No related tags found
No related merge requests found
......@@ -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()));
}
}
......
......@@ -55,6 +55,8 @@ public slots:
void commandFinishedGotoLine(bool ok, int exitCode, const QVariant &v);
private slots:
void checkoutChange();
void resetChange();
void cherryPickChange();
void revertChange();
void stageDiffChunk();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment