Git: Introduce StashGuard

Offers the user to stash changes (if relevant), stores
the results and pops the stash when it goes out of scope
(unless disabled)

Change-Id: Ibc0d2a5d3e3c953062fb17ecba903ca814524837
Reviewed-by: Tobias Hunger <tobias.hunger@digia.com>
This commit is contained in:
Orgad Shaneh
2013-01-24 12:11:01 +02:00
parent c670a66fe1
commit 5551c1e906
8 changed files with 102 additions and 86 deletions

View File

@@ -1567,16 +1567,6 @@ static inline int askWithDetailedText(QWidget *parent,
return msgBox.exec();
}
// Convenience that pops up an msg box.
GitClient::StashResult GitClient::ensureStash(const QString &workingDirectory, const QString &keyword, QString *message)
{
QString errorMessage;
const StashResult sr = ensureStash(workingDirectory, keyword, true, message, &errorMessage);
if (sr == StashFailed)
outputWindow()->appendError(errorMessage);
return sr;
}
// Ensure that changed files are stashed before a pull or similar
GitClient::StashResult GitClient::ensureStash(const QString &workingDirectory,
const QString &keyword,
@@ -2540,6 +2530,41 @@ unsigned GitClient::synchronousGitVersion(QString *errorMessage) const
return version(major, minor, patch);
}
GitClient::StashGuard::StashGuard(const QString &workingDirectory, const QString &keyword) :
pop(true),
workingDir(workingDirectory)
{
client = GitPlugin::instance()->gitClient();
QString errorMessage;
stashResult = client->ensureStash(workingDir, keyword, true, &message, &errorMessage);
if (stashResult == GitClient::StashFailed)
VcsBase::VcsBaseOutputWindow::instance()->appendError(errorMessage);
}
GitClient::StashGuard::~StashGuard()
{
if (pop && stashResult == GitClient::Stashed)
client->stashPop(workingDir, message);
}
void GitClient::StashGuard::preventPop()
{
pop = false;
}
bool GitClient::StashGuard::stashingFailed(bool includeNotStashed) const
{
switch (stashResult) {
case GitClient::StashCanceled:
case GitClient::StashFailed:
return true;
case GitClient::NotStashed:
return includeNotStashed;
default:
return false;
}
}
} // namespace Internal
} // namespace Git