From 4c5cf6bc86ff7a5c94e4ed7004406856e3ebf93c Mon Sep 17 00:00:00 2001 From: Andre Hartmann Date: Thu, 26 Dec 2019 18:14:04 +0100 Subject: [PATCH] Git: Update status on upstream change in branch view When a new tracking branch was selected, the branch view still showed the old ahead/behind information. Change-Id: Ic4a201da0ec38788a02ef03770a30cca6528ceb3 Reviewed-by: Orgad Shaneh --- src/plugins/git/branchmodel.cpp | 28 +++++++++++++++++----------- src/plugins/git/branchmodel.h | 1 + 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/src/plugins/git/branchmodel.cpp b/src/plugins/git/branchmodel.cpp index ae4d6fd839e..8d90200952b 100644 --- a/src/plugins/git/branchmodel.cpp +++ b/src/plugins/git/branchmodel.cpp @@ -731,6 +731,7 @@ void BranchModel::setRemoteTracking(const QModelIndex &trackingIndex) const QString tracking = fullName(trackingIndex, true); d->client->synchronousSetTrackingBranch(d->workingDirectory, currentName, tracking); d->currentBranch->tracking = shortTracking; + updateUpstreamStatus(d->currentBranch); emit dataChanged(current, current); } @@ -840,17 +841,7 @@ void BranchModel::Private::parseOutputLine(const QString &line, bool force) root->insert(nameParts, newNode); if (current) currentBranch = newNode; - if (newNode->tracking.isEmpty()) - return; - VcsCommand *command = client->asyncUpstreamStatus(workingDirectory, newNode->name, newNode->tracking); - QObject::connect(command, &VcsCommand::stdOutText, newNode, [this, newNode](const QString &text) { - const QStringList split = text.trimmed().split('\t'); - QTC_ASSERT(split.size() == 2, return); - - newNode->setUpstreamStatus(UpstreamStatus(split.at(0).toInt(), split.at(1).toInt())); - const QModelIndex idx = q->nodeToIndex(newNode, 0); - emit q->dataChanged(idx, idx); - }); + q->updateUpstreamStatus(newNode); } void BranchModel::Private::flushOldEntries() @@ -898,6 +889,21 @@ void BranchModel::removeNode(const QModelIndex &idx) } } +void BranchModel::updateUpstreamStatus(BranchNode *node) +{ + if (node->tracking.isEmpty()) + return; + VcsCommand *command = d->client->asyncUpstreamStatus(d->workingDirectory, node->name, node->tracking); + QObject::connect(command, &VcsCommand::stdOutText, node, [this, node](const QString &text) { + const QStringList split = text.trimmed().split('\t'); + QTC_ASSERT(split.size() == 2, return); + + node->setUpstreamStatus(UpstreamStatus(split.at(0).toInt(), split.at(1).toInt())); + const QModelIndex idx = nodeToIndex(node, 0); + emit dataChanged(idx, idx); + }); +} + QString BranchModel::toolTip(const QString &sha) const { // Show the sha description excluding diff as toolTip diff --git a/src/plugins/git/branchmodel.h b/src/plugins/git/branchmodel.h index 2a0de65bbe4..7a2fa285123 100644 --- a/src/plugins/git/branchmodel.h +++ b/src/plugins/git/branchmodel.h @@ -92,6 +92,7 @@ private: BranchNode *indexToNode(const QModelIndex &index) const; QModelIndex nodeToIndex(BranchNode *node, int column) const; void removeNode(const QModelIndex &idx); + void updateUpstreamStatus(BranchNode *node); QString toolTip(const QString &sha) const;