forked from qt-creator/qt-creator
Git: Introduce Recover Deleted Files action
Change-Id: I913c07522a8ca82366fd142597430c02e53faa27 Reviewed-by: André Hartmann <aha_1980@gmx.de> Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
This commit is contained in:
committed by
Orgad Shaneh
parent
b1239d6c4c
commit
a8ddaafca4
@@ -993,6 +993,23 @@ void GitClient::reset(const QString &workingDirectory, const QString &argument,
|
||||
vcsExec(workingDirectory, arguments, nullptr, true, flags);
|
||||
}
|
||||
|
||||
void GitClient::recoverDeletedFiles(const QString &workingDirectory)
|
||||
{
|
||||
const SynchronousProcessResponse response =
|
||||
vcsFullySynchronousExec(workingDirectory, {"ls-files", "--deleted"},
|
||||
VcsCommand::SuppressCommandLogging);
|
||||
if (response.result == SynchronousProcessResponse::Finished) {
|
||||
const QString stdOut = response.stdOut().trimmed();
|
||||
if (stdOut.isEmpty()) {
|
||||
VcsOutputWindow::appendError(tr("Nothing to recover"));
|
||||
return;
|
||||
}
|
||||
const QStringList files = stdOut.split('\n');
|
||||
synchronousCheckoutFiles(workingDirectory, files, QString(), nullptr, false);
|
||||
VcsOutputWindow::append(tr("Files recovered"), VcsOutputWindow::Message);
|
||||
}
|
||||
}
|
||||
|
||||
void GitClient::addFile(const QString &workingDirectory, const QString &fileName)
|
||||
{
|
||||
vcsExec(workingDirectory, {"add", fileName});
|
||||
|
@@ -151,6 +151,7 @@ public:
|
||||
const QString &workingDir, const QString &file, const QString &revision = QString(),
|
||||
int lineNumber = -1, const QStringList &extraOptions = QStringList()) override;
|
||||
void reset(const QString &workingDirectory, const QString &argument, const QString &commit = QString());
|
||||
void recoverDeletedFiles(const QString &workingDirectory);
|
||||
void addFile(const QString &workingDirectory, const QString &fileName);
|
||||
bool synchronousLog(const QString &workingDirectory, const QStringList &arguments,
|
||||
QString *output, QString *errorMessage = nullptr,
|
||||
|
@@ -424,6 +424,9 @@ bool GitPlugin::initialize(const QStringList &arguments, QString *errorMessage)
|
||||
createRepositoryAction(localRepositoryMenu, tr("Reset..."), "Git.Reset",
|
||||
context, true, std::bind(&GitPlugin::resetRepository, this));
|
||||
|
||||
createRepositoryAction(localRepositoryMenu, tr("Recover Deleted Files"), "Git.RecoverDeleted",
|
||||
context, true, std::bind(&GitPlugin::recoverDeletedFiles, this));
|
||||
|
||||
m_interactiveRebaseAction
|
||||
= createRepositoryAction(localRepositoryMenu,
|
||||
tr("Interactive Rebase..."), "Git.InteractiveRebase",
|
||||
@@ -807,6 +810,15 @@ void GitPlugin::resetRepository()
|
||||
m_gitClient->reset(topLevel, dialog.resetFlag(), dialog.commit());
|
||||
}
|
||||
|
||||
void GitPlugin::recoverDeletedFiles()
|
||||
{
|
||||
if (!DocumentManager::saveAllModifiedDocuments())
|
||||
return;
|
||||
const VcsBasePluginState state = currentState();
|
||||
QTC_ASSERT(state.hasTopLevel(), return);
|
||||
m_gitClient->recoverDeletedFiles(state.topLevel());
|
||||
}
|
||||
|
||||
void GitPlugin::startRebase()
|
||||
{
|
||||
if (!DocumentManager::saveAllModifiedDocuments())
|
||||
|
@@ -112,6 +112,7 @@ private:
|
||||
void logRepository();
|
||||
void undoFileChanges(bool revertStaging);
|
||||
void resetRepository();
|
||||
void recoverDeletedFiles();
|
||||
void startRebase();
|
||||
void startChangeRelatedAction(const Core::Id &id);
|
||||
void stageFile();
|
||||
|
Reference in New Issue
Block a user