summaryrefslogtreecommitdiff
path: root/src/plugins/git/gitplugin.cpp
diff options
context:
space:
mode:
authorOrgad Shaneh <orgad.shaneh@audiocodes.com>2013-06-05 22:51:32 +0300
committerOrgad Shaneh <orgads@gmail.com>2013-06-11 22:46:57 +0200
commit2073a0660f2d3203acd15b2e6a29088443020145 (patch)
treec29f22e260307480daf5a8bdf88a4422902c9888 /src/plugins/git/gitplugin.cpp
parente181ae009b8aa3b493a157b6ea0d61ab83ce61ec (diff)
downloadqt-creator-2073a0660f2d3203acd15b2e6a29088443020145.tar.gz
Git: Ensure documents are saved before executing destructive calls
Change-Id: I9ec0ae0ff6a1b70e5d4c322dbf2e53be57e3009f Reviewed-by: Petar Perisin <petar.perisin@gmail.com> Reviewed-by: Tobias Hunger <tobias.hunger@digia.com>
Diffstat (limited to 'src/plugins/git/gitplugin.cpp')
-rw-r--r--src/plugins/git/gitplugin.cpp24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/plugins/git/gitplugin.cpp b/src/plugins/git/gitplugin.cpp
index b3d8562d11..6f051f9af3 100644
--- a/src/plugins/git/gitplugin.cpp
+++ b/src/plugins/git/gitplugin.cpp
@@ -712,6 +712,14 @@ void GitPlugin::submitEditorMerge(const QStringList &unmerged)
m_gitClient->merge(m_submitRepository, unmerged);
}
+static bool ensureAllDocumentsSaved()
+{
+ bool cancelled;
+ Core::DocumentManager::saveModifiedDocuments(Core::DocumentManager::modifiedDocuments(),
+ &cancelled);
+ return !cancelled;
+}
+
void GitPlugin::diffCurrentFile()
{
const VcsBase::VcsBasePluginState state = currentState();
@@ -764,6 +772,8 @@ void GitPlugin::logRepository()
void GitPlugin::undoFileChanges(bool revertStaging)
{
+ if (!ensureAllDocumentsSaved())
+ return;
const VcsBase::VcsBasePluginState state = currentState();
QTC_ASSERT(state.hasFile(), return);
Core::FileChangeBlocker fcb(state.currentFile());
@@ -772,11 +782,15 @@ void GitPlugin::undoFileChanges(bool revertStaging)
void GitPlugin::undoUnstagedFileChanges()
{
+ if (!ensureAllDocumentsSaved())
+ return;
undoFileChanges(false);
}
void GitPlugin::resetRepository()
{
+ if (!ensureAllDocumentsSaved())
+ return;
const VcsBase::VcsBasePluginState state = currentState();
QTC_ASSERT(state.hasTopLevel(), return);
QString topLevel = state.topLevel();
@@ -789,6 +803,8 @@ void GitPlugin::resetRepository()
void GitPlugin::startRebase()
{
+ if (!ensureAllDocumentsSaved())
+ return;
const VcsBase::VcsBasePluginState state = currentState();
QTC_ASSERT(state.hasTopLevel(), return);
const QString topLevel = state.topLevel();
@@ -828,6 +844,8 @@ void GitPlugin::startChangeRelatedAction()
return;
}
+ if (!ensureAllDocumentsSaved())
+ return;
QString command;
bool (GitClient::*commandFunction)(const QString&, const QString&);
switch (dialog.command()) {
@@ -1085,6 +1103,8 @@ void GitPlugin::fetch()
void GitPlugin::pull()
{
+ if (!ensureAllDocumentsSaved())
+ return;
const VcsBase::VcsBasePluginState state = currentState();
QTC_ASSERT(state.hasTopLevel(), return);
QString topLevel = state.topLevel();
@@ -1120,6 +1140,8 @@ void GitPlugin::startMergeTool()
void GitPlugin::continueOrAbortCommand()
{
+ if (!ensureAllDocumentsSaved())
+ return;
const VcsBase::VcsBasePluginState state = currentState();
QTC_ASSERT(state.hasTopLevel(), return);
QObject *action = QObject::sender();
@@ -1278,6 +1300,8 @@ void GitPlugin::applyPatch(const QString &workingDirectory, QString file)
void GitPlugin::stash()
{
+ if (!ensureAllDocumentsSaved())
+ return;
// Simple stash without prompt, reset repo.
const VcsBase::VcsBasePluginState state = currentState();
QTC_ASSERT(state.hasTopLevel(), return);