Commit 89d16332 authored by Orgad Shaneh's avatar Orgad Shaneh Committed by Orgad Shaneh
Browse files

Git: Replace synchronousStash with ensureStash



When flags are not used. syncStash doesn't return result,
which can be useful for StashGuard

Change-Id: I1327b5d8d10410e7a3b9fdb07a03b476d5abcdc4
Reviewed-by: default avatarTobias Hunger <tobias.hunger@digia.com>
parent 8b67ae73
......@@ -188,7 +188,7 @@ void BranchDialog::checkout()
QString stashMessage;
if (branchCheckoutDialog.makeStashOfCurrentBranch()
|| branchCheckoutDialog.moveLocalChangesToNextBranch()) {
stashMessage = gitClient->synchronousStash(m_repository, currentBranch + QLatin1String("-AutoStash"));
gitClient->ensureStash(m_repository, currentBranch + QLatin1String("-AutoStash"), false, &stashMessage);
} else if (branchCheckoutDialog.discardLocalChanges()) {
gitClient->synchronousReset(m_repository);
}
......@@ -259,7 +259,7 @@ void BranchDialog::merge()
QString stashMessage;
if (gitClient->gitStatus(m_repository, StatusMode(NoUntracked | NoSubmodules)) == GitClient::StatusChanged)
stashMessage = gitClient->synchronousStash(m_repository, QLatin1String("merge"));
gitClient->ensureStash(m_repository, QLatin1String("merge"), false, &stashMessage);
if (gitClient->synchronousMerge(m_repository, branch) && (!stashMessage.isEmpty()))
gitClient->stashPop(m_repository);
......@@ -276,7 +276,7 @@ void BranchDialog::rebase()
QString stashMessage;
if (gitClient->gitStatus(m_repository, StatusMode(NoUntracked | NoSubmodules)) == GitClient::StatusChanged)
stashMessage = gitClient->synchronousStash(m_repository, QLatin1String("rebase"));
gitClient->ensureStash(m_repository, QLatin1String("rebase"), false, &stashMessage);
if (gitClient->synchronousRebase(m_repository, baseBranch) && (!stashMessage.isEmpty()))
gitClient->stashPop(m_repository);
......
......@@ -1578,7 +1578,11 @@ GitClient::StashResult GitClient::ensureStash(const QString &workingDirectory, c
}
// Ensure that changed files are stashed before a pull or similar
GitClient::StashResult GitClient::ensureStash(const QString &workingDirectory, const QString &keyword, QString *message, QString *errorMessage)
GitClient::StashResult GitClient::ensureStash(const QString &workingDirectory,
const QString &keyword,
bool askUser,
QString *message,
QString *errorMessage)
{
QString statusOutput;
switch (gitStatus(workingDirectory, StatusMode(NoUntracked | NoSubmodules),
......@@ -1591,23 +1595,24 @@ GitClient::StashResult GitClient::ensureStash(const QString &workingDirectory, c
return StashFailed;
}
const int answer = askWithDetailedText(Core::ICore::mainWindow(), tr("Changes"),
tr("Would you like to stash your changes?"),
statusOutput, QMessageBox::Yes, QMessageBox::Yes|QMessageBox::No|QMessageBox::Cancel);
switch (answer) {
case QMessageBox::Cancel:
return StashCanceled;
case QMessageBox::Yes: {
const QString stashMessage = creatorStashMessage(keyword);
if (!executeSynchronousStash(workingDirectory, stashMessage, errorMessage))
return StashFailed;
if (message)
*message = stashMessage;
break;
}
case QMessageBox::No: // At your own risk, so.
return NotStashed;
if (askUser) {
const int answer = askWithDetailedText(Core::ICore::mainWindow(), tr("Changes"),
tr("Would you like to stash your changes?"),
statusOutput, QMessageBox::Yes, QMessageBox::Yes|QMessageBox::No|QMessageBox::Cancel);
switch (answer) {
case QMessageBox::Cancel:
return StashCanceled;
case QMessageBox::No: // At your own risk, so.
return NotStashed;
default:
break;
}
}
const QString stashMessage = creatorStashMessage(keyword);
if (!executeSynchronousStash(workingDirectory, stashMessage, errorMessage))
return StashFailed;
if (message)
*message = stashMessage;
return Stashed;
}
......
......@@ -243,6 +243,9 @@ public:
bool isValidRevision(const QString &revision) const;
StashResult ensureStash(const QString &workingDirectory, const QString &keyword, bool askUser,
QString *message, QString *errorMessage = 0);
static QString msgNoChangedFiles();
static const char *noColorOption;
......
......@@ -1125,7 +1125,8 @@ void GitPlugin::stash()
// Simple stash without prompt, reset repo.
const VcsBase::VcsBasePluginState state = currentState();
QTC_ASSERT(state.hasTopLevel(), return);
const QString id = m_gitClient->synchronousStash(state.topLevel(), QString(), 0);
QString id;
gitClient()->ensureStash(state.topLevel(), QString(), false, &id);
if (!id.isEmpty() && m_stashDialog)
m_stashDialog->refresh(state.topLevel(), true);
}
......@@ -1135,7 +1136,8 @@ void GitPlugin::stashSnapshot()
// Prompt for description, restore immediately and keep on working.
const VcsBase::VcsBasePluginState state = currentState();
QTC_ASSERT(state.hasTopLevel(), return);
const QString id = m_gitClient->synchronousStash(state.topLevel(), QString(), GitClient::StashImmediateRestore|GitClient::StashPromptDescription);
const QString id = m_gitClient->synchronousStash(state.topLevel(), QString(),
GitClient::StashImmediateRestore|GitClient::StashPromptDescription);
if (!id.isEmpty() && m_stashDialog)
m_stashDialog->refresh(state.topLevel(), true);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment