Git: Fix popping of branch-stash after checkout

Checking out a branch that has a saved stash, when
Pop branch stash is checked, is broken since checkout
became asynchronous.

We must wait for checkout to complete before popping
the branch stash.

Change-Id: Ia4d43649e742ced0121ffe106986b4d6ed1e7b38
Reviewed-by: André Hartmann <aha_1980@gmx.de>
This commit is contained in:
Orgad Shaneh
2019-06-26 16:15:12 +03:00
committed by Orgad Shaneh
parent 0d7f33aa71
commit a1ba347fa5
5 changed files with 34 additions and 23 deletions

View File

@@ -41,6 +41,7 @@
#include <utils/navigationtreeview.h>
#include <utils/qtcassert.h>
#include <utils/utilsicons.h>
#include <vcsbase/vcscommand.h>
#include <vcsbase/vcsoutputwindow.h>
#include <QDir>
@@ -382,21 +383,28 @@ bool BranchView::checkout()
return false;
}
m_model->checkoutBranch(selected);
QString stashName;
client->synchronousStashList(m_repository, &stashes);
for (const Stash &stash : qAsConst(stashes)) {
if (stash.message.startsWith(popMessageStart)) {
stashName = stash.name;
break;
}
VcsBase::VcsCommand *command = m_model->checkoutBranch(selected);
const bool moveChanges = branchCheckoutDialog.moveLocalChangesToNextBranch();
const bool popStash = branchCheckoutDialog.popStashOfNextBranch();
if (command && (moveChanges || popStash)) {
connect(command, &VcsBase::VcsCommand::finished,
this, [this, client, popMessageStart, moveChanges, popStash] {
if (moveChanges) {
client->endStashScope(m_repository);
} else if (popStash) {
QList<Stash> stashes;
QString stashName;
client->synchronousStashList(m_repository, &stashes);
for (const Stash &stash : qAsConst(stashes)) {
if (stash.message.startsWith(popMessageStart)) {
stashName = stash.name;
break;
}
}
client->synchronousStashRestore(m_repository, stashName, true);
}
});
}
if (branchCheckoutDialog.moveLocalChangesToNextBranch())
client->endStashScope(m_repository);
else if (branchCheckoutDialog.popStashOfNextBranch())
client->synchronousStashRestore(m_repository, stashName, true);
}
if (QTC_GUARD(m_branchView))