Commit 177f7740 authored by Orgad Shaneh's avatar Orgad Shaneh

Git: Use StashGuard for merge and rebase

Change-Id: I7c9059396aaac78c769518b34c7bf68bfe9932ec
Reviewed-by: default avatarTobias Hunger <tobias.hunger@digia.com>
Reviewed-by: default avatarPetar Perisin <petar.perisin@gmail.com>
parent 5551c1e9
......@@ -255,14 +255,9 @@ void BranchDialog::merge()
QTC_CHECK(idx != m_model->currentBranch()); // otherwise the button would not be enabled!
const QString branch = m_model->branchName(idx);
GitClient *gitClient = GitPlugin::instance()->gitClient();
QString stashMessage;
if (gitClient->gitStatus(m_repository, StatusMode(NoUntracked | NoSubmodules)) == GitClient::StatusChanged)
gitClient->ensureStash(m_repository, QLatin1String("merge"), false, &stashMessage);
if (gitClient->synchronousMerge(m_repository, branch) && !stashMessage.isEmpty())
gitClient->stashPop(m_repository, stashMessage);
GitClient::StashGuard stashGuard(m_repository, QLatin1String("merge"), false);
if (!GitPlugin::instance()->gitClient()->synchronousMerge(m_repository, branch))
stashGuard.preventPop();
}
void BranchDialog::rebase()
......@@ -272,14 +267,9 @@ void BranchDialog::rebase()
QTC_CHECK(idx != m_model->currentBranch()); // otherwise the button would not be enabled!
const QString baseBranch = m_model->branchName(idx);
GitClient *gitClient = GitPlugin::instance()->gitClient();
QString stashMessage;
if (gitClient->gitStatus(m_repository, StatusMode(NoUntracked | NoSubmodules)) == GitClient::StatusChanged)
gitClient->ensureStash(m_repository, QLatin1String("rebase"), false, &stashMessage);
if (gitClient->synchronousRebase(m_repository, baseBranch) && !stashMessage.isEmpty())
gitClient->stashPop(m_repository, stashMessage);
GitClient::StashGuard stashGuard(m_repository, QLatin1String("rebase"), false);
if (!GitPlugin::instance()->gitClient()->synchronousRebase(m_repository, baseBranch))
stashGuard.preventPop();
}
void BranchDialog::changeEvent(QEvent *e)
......
......@@ -2530,13 +2530,13 @@ unsigned GitClient::synchronousGitVersion(QString *errorMessage) const
return version(major, minor, patch);
}
GitClient::StashGuard::StashGuard(const QString &workingDirectory, const QString &keyword) :
GitClient::StashGuard::StashGuard(const QString &workingDirectory, const QString &keyword, bool askUser) :
pop(true),
workingDir(workingDirectory)
{
client = GitPlugin::instance()->gitClient();
QString errorMessage;
stashResult = client->ensureStash(workingDir, keyword, true, &message, &errorMessage);
stashResult = client->ensureStash(workingDir, keyword, askUser, &message, &errorMessage);
if (stashResult == GitClient::StashFailed)
VcsBase::VcsBaseOutputWindow::instance()->appendError(errorMessage);
}
......
......@@ -88,7 +88,7 @@ public:
class StashGuard
{
public:
StashGuard(const QString &workingDirectory, const QString &keyword);
StashGuard(const QString &workingDirectory, const QString &keyword, bool askUser = true);
~StashGuard();
void preventPop();
......
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