From 18906fac4f0f7146976de343ab00c79f43af4fa4 Mon Sep 17 00:00:00 2001 From: Orgad Shaneh Date: Wed, 26 Feb 2014 15:22:06 +0200 Subject: [PATCH] Git: Protect against removal of the "Local Branches" node ... When a single local branch is being removed Change-Id: I4321d045ebb6faaf5f864ff33cb4f34c15d2264b Reviewed-by: Tobias Hunger --- src/plugins/git/branchmodel.cpp | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/plugins/git/branchmodel.cpp b/src/plugins/git/branchmodel.cpp index 75e5c7cbc93..93cce7de063 100644 --- a/src/plugins/git/branchmodel.cpp +++ b/src/plugins/git/branchmodel.cpp @@ -692,14 +692,18 @@ QModelIndex BranchModel::nodeToIndex(BranchNode *node) const void BranchModel::removeNode(const QModelIndex &idx) { - QModelIndex tmp = idx; // tmp is a leaf, so count must be 0. - while (indexToNode(tmp)->count() == 0) { - QModelIndex tmpParent = parent(tmp); - beginRemoveRows(tmpParent, tmp.row(), tmp.row()); - indexToNode(tmpParent)->children.removeAt(tmp.row()); - delete indexToNode(tmp); + QModelIndex nodeIndex = idx; // idx is a leaf, so count must be 0. + BranchNode *node = indexToNode(nodeIndex); + while (node->count() == 0 && node->parent != m_rootNode) { + BranchNode *parentNode = node->parent; + const QModelIndex parentIndex = nodeToIndex(parentNode); + const int nodeRow = nodeIndex.row(); + beginRemoveRows(parentIndex, nodeRow, nodeRow); + parentNode->children.removeAt(nodeRow); + delete node; endRemoveRows(); - tmp = tmpParent; + node = parentNode; + nodeIndex = parentIndex; } }