diff --git a/src/plugins/git/branchdialog.cpp b/src/plugins/git/branchdialog.cpp index 848fb293e9cfaa2019d60a3411f9d4b4a6c60746..d4b68d74d5dcfb1fd7daa9889148ed42b1c7611f 100644 --- a/src/plugins/git/branchdialog.cpp +++ b/src/plugins/git/branchdialog.cpp @@ -121,12 +121,13 @@ void BranchDialog::refresh() void BranchDialog::add() { - QString trackedBranch = m_model->branchName(selectedIndex()); - bool isLocal = m_model->isLocal(selectedIndex()); + QModelIndex trackedIndex = selectedIndex(); + QString trackedBranch = m_model->branchName(trackedIndex); if (trackedBranch.isEmpty()) { - trackedBranch = m_model->branchName(m_model->currentBranch()); - isLocal = true; + trackedIndex = m_model->currentBranch(); + trackedBranch = m_model->branchName(trackedIndex); } + const bool isLocal = m_model->isLocal(trackedIndex); QStringList localNames = m_model->localBranchNames(); @@ -143,7 +144,7 @@ void BranchDialog::add() branchAddDialog.setTrackedBranchName(trackedBranch, !isLocal); if (branchAddDialog.exec() == QDialog::Accepted && m_model) { - QModelIndex idx = m_model->addBranch(branchAddDialog.branchName(), branchAddDialog.track(), trackedBranch); + QModelIndex idx = m_model->addBranch(branchAddDialog.branchName(), branchAddDialog.track(), trackedIndex); m_ui->branchView->selectionModel()->select(idx, QItemSelectionModel::Clear | QItemSelectionModel::Select | QItemSelectionModel::Current); diff --git a/src/plugins/git/branchmodel.cpp b/src/plugins/git/branchmodel.cpp index 1bcc8ac31b7c8ae90c664a19b42e0a22fbcc1490..132662c652dc81035af8a6ca879001f298dd3414 100644 --- a/src/plugins/git/branchmodel.cpp +++ b/src/plugins/git/branchmodel.cpp @@ -513,19 +513,20 @@ bool BranchModel::branchIsMerged(const QModelIndex &idx) return false; } -QModelIndex BranchModel::addBranch(const QString &branchName, bool track, const QString &startPoint) +QModelIndex BranchModel::addBranch(const QString &name, bool track, const QModelIndex &startPoint) { if (!m_rootNode || !m_rootNode->count()) return QModelIndex(); + const QString trackedBranch = branchName(startPoint); QString output; QString errorMessage; QStringList args; args << (track ? QLatin1String("--track") : QLatin1String("--no-track")); - args << branchName; - if (!startPoint.isEmpty()) - args << startPoint; + args << name; + if (!trackedBranch.isEmpty()) + args << trackedBranch; if (!m_client->synchronousBranchCmd(m_workingDirectory, args, &output, &errorMessage)) { VcsBase::VcsBaseOutputWindow::instance()->appendError(errorMessage); @@ -535,21 +536,10 @@ QModelIndex BranchModel::addBranch(const QString &branchName, bool track, const BranchNode *local = m_rootNode->children.at(0); int pos = 0; for (pos = 0; pos < local->count(); ++pos) { - if (local->children.at(pos)->name > branchName) + if (local->children.at(pos)->name > name) break; } - BranchNode *newNode = new BranchNode(branchName); - - // find the sha of the new branch: - output = toolTip(branchName); // abuse toolTip to get the data;-) - QStringList lines = output.split(QLatin1Char('\n')); - foreach (const QString &l, lines) { - if (l.startsWith(QLatin1String("commit "))) { - newNode->sha = l.mid(7, 8); - break; - } - } - + BranchNode *newNode = new BranchNode(name, sha(startPoint), trackedBranch); beginInsertRows(index(0, 0), pos, pos); newNode->parent = local; local->children.insert(pos, newNode); diff --git a/src/plugins/git/branchmodel.h b/src/plugins/git/branchmodel.h index c386e258f364c6d8d390de4f8388c99e8414e4b9..a8f13ffba8fbd0aac09e4783e6e18a884f0e3480 100644 --- a/src/plugins/git/branchmodel.h +++ b/src/plugins/git/branchmodel.h @@ -78,7 +78,7 @@ public: void removeBranch(const QModelIndex &idx); void checkoutBranch(const QModelIndex &idx); bool branchIsMerged(const QModelIndex &idx); - QModelIndex addBranch(const QString &branchName, bool track, const QString &trackedBranch); + QModelIndex addBranch(const QString &name, bool track, const QModelIndex &trackedBranch); private: void parseOutputLine(const QString &line);