diff options
author | Orgad Shaneh <orgad.shaneh@audiocodes.com> | 2013-06-17 14:44:03 +0300 |
---|---|---|
committer | Orgad Shaneh <orgads@gmail.com> | 2013-06-17 13:51:27 +0200 |
commit | 744d5d51aba72beffd2c72f0639e3694a63fd335 (patch) | |
tree | 2e0a3285398794ba9640aaeeeb50bdc10128f25f /src/plugins/git | |
parent | 40f3efbc21b71db463d17c813bcfb5d250a062fb (diff) | |
download | qt-creator-744d5d51aba72beffd2c72f0639e3694a63fd335.tar.gz |
Git: Display tracking branch for newly created branches
+ Get rid of a workaround done for retrieving sha
Change-Id: I4b7a6c6d9e9be5766f4fc540dc8b15037eb7948c
Reviewed-by: Tobias Hunger <tobias.hunger@digia.com>
Diffstat (limited to 'src/plugins/git')
-rw-r--r-- | src/plugins/git/branchdialog.cpp | 11 | ||||
-rw-r--r-- | src/plugins/git/branchmodel.cpp | 24 | ||||
-rw-r--r-- | src/plugins/git/branchmodel.h | 2 |
3 files changed, 14 insertions, 23 deletions
diff --git a/src/plugins/git/branchdialog.cpp b/src/plugins/git/branchdialog.cpp index 848fb293e9..d4b68d74d5 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 1bcc8ac31b..132662c652 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 c386e258f3..a8f13ffba8 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); |