Git: Use StashGuard for merge and rebase

Change-Id: I7c9059396aaac78c769518b34c7bf68bfe9932ec
Reviewed-by: Tobias Hunger <tobias.hunger@digia.com>
Reviewed-by: Petar Perisin <petar.perisin@gmail.com>
This commit is contained in:
Orgad Shaneh
2013-01-22 21:27:54 +02:00
parent 5551c1e906
commit 177f774036
3 changed files with 9 additions and 19 deletions

View File

@@ -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)

View File

@@ -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);
}

View File

@@ -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();