Git: Update current branch after some operations

... to refresh the branch view upstream status.

No need for a full model update here, only the current
branch is influenced.

Change-Id: I6bd17a841988b36221e5015a5858071d33a7b5e5
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
This commit is contained in:
Andre Hartmann
2019-12-27 11:52:59 +01:00
committed by André Hartmann
parent d29650b3ea
commit da6972e0a9
7 changed files with 29 additions and 5 deletions

View File

@@ -759,6 +759,13 @@ Utils::optional<QString> BranchModel::remoteName(const QModelIndex &idx) const
return Utils::nullopt;
}
void BranchModel::refreshCurrentBranch()
{
const QModelIndex currentIndex = currentBranch();
BranchNode *node = indexToNode(currentIndex);
updateUpstreamStatus(node);
}
void BranchModel::Private::parseOutputLine(const QString &line, bool force)
{
if (line.size() < 3)

View File

@@ -86,6 +86,7 @@ public:
void setRemoteTracking(const QModelIndex &trackingIndex);
void setOldBranchesIncluded(bool value);
Utils::optional<QString> remoteName(const QModelIndex &idx) const;
void refreshCurrentBranch();
private:
void setCurrentBranch();

View File

@@ -169,6 +169,11 @@ void BranchView::refresh(const QString &repository, bool force)
VcsBase::VcsOutputWindow::appendError(errorMessage);
}
void BranchView::refreshCurrentBranch()
{
m_model->refreshCurrentBranch();
}
QToolButton *BranchView::addButton() const
{
return m_addButton;

View File

@@ -57,6 +57,7 @@ public:
void refreshIfSame(const QString &repository);
void refresh(const QString &repository, bool force);
void refreshCurrentBranch();
QToolButton *addButton() const;
QToolButton *refreshButton() const;

View File

@@ -2843,6 +2843,7 @@ bool GitClient::addAndCommit(const QString &repositoryDirectory,
if (resp.result == SynchronousProcessResponse::Finished) {
VcsOutputWindow::appendMessage(msgCommitted(amendSHA1, commitCount));
VcsOutputWindow::appendError(stdErr);
GitPlugin::instance()->updateCurrentBranch();
return true;
} else {
VcsOutputWindow::appendError(tr("Cannot commit %n files: %1\n", nullptr, commitCount).arg(stdErr));
@@ -3175,8 +3176,11 @@ void GitClient::push(const QString &workingDirectory, const QStringList &pushArg
.arg(QString::number(warnColor.rgba(), 16)),
QMessageBox::Yes | QMessageBox::No,
QMessageBox::No) == QMessageBox::Yes) {
vcsExec(workingDirectory, QStringList({"push", "--force-with-lease"}) + pushArgs,
VcsCommand *rePushCommand = vcsExec(workingDirectory,
QStringList({"push", "--force-with-lease"}) + pushArgs,
nullptr, true, VcsCommand::ShowSuccessMessage);
connect(rePushCommand, &VcsCommand::success,
this, []() { GitPlugin::instance()->updateCurrentBranch(); });
}
break;
}
@@ -3197,13 +3201,12 @@ void GitClient::push(const QString &workingDirectory, const QStringList &pushArg
fallbackCommandParts.mid(1),
nullptr, true, VcsCommand::ShowSuccessMessage);
connect(rePushCommand, &VcsCommand::success,
this, [workingDirectory]() {
GitPlugin::instance()->updateBranches(workingDirectory);
}
);
this, []() { GitPlugin::instance()->updateCurrentBranch(); });
}
break;
}
} else {
GitPlugin::instance()->updateCurrentBranch();
}
});
}

View File

@@ -1416,6 +1416,12 @@ void GitPlugin::updateBranches(const QString &repository)
m_branchViewFactory->view()->refreshIfSame(repository);
}
void GitPlugin::updateCurrentBranch()
{
if (m_branchViewFactory && m_branchViewFactory->view())
m_branchViewFactory->view()->refreshCurrentBranch();
}
QObject *GitPlugin::remoteCommand(const QStringList &options, const QString &workingDirectory,
const QStringList &)
{

View File

@@ -89,6 +89,7 @@ public:
static QString invalidBranchAndRemoteNamePattern();
void startCommit(CommitType commitType = SimpleCommit);
void updateBranches(const QString &repository);
void updateCurrentBranch();
QObject *remoteCommand(const QStringList &options, const QString &workingDirectory,
const QStringList &args) override;