Git: Add push to branch view

Allows pushing the selected local branch to any remote branch.

Change-Id: I6fb9ee8e1659070c1c759fe64b713fb2235c8816
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
This commit is contained in:
Andre Hartmann
2018-10-21 13:34:24 +02:00
committed by André Hartmann
parent 82e997cf59
commit 44205a961e
2 changed files with 21 additions and 0 deletions

View File

@@ -246,6 +246,10 @@ void BranchView::slotCustomContextMenu(const QPoint &point)
contextMenu.addAction(tr("Track"), this, [this] {
m_model->setRemoteTracking(selectedIndex());
});
if (!isLocal) {
contextMenu.addSeparator();
contextMenu.addAction(tr("&Push"), this, &BranchView::push);
}
}
}
contextMenu.exec(m_branchView->viewport()->mapToGlobal(point));
@@ -531,6 +535,22 @@ void BranchView::log(const QModelIndex &idx)
GitPlugin::client()->log(m_repository, QString(), false, {branchName});
}
void BranchView::push()
{
const QModelIndex selected = selectedIndex();
QTC_CHECK(selected != m_model->currentBranch());
const QString fullTargetName = m_model->fullName(selected);
const int pos = fullTargetName.indexOf('/');
const QString localBranch = m_model->fullName(m_model->currentBranch());
const QString remoteName = fullTargetName.left(pos);
const QString remoteBranch = fullTargetName.mid(pos + 1);
const QStringList pushArgs = {remoteName, localBranch + ':' + remoteBranch};
GitPlugin::client()->push(m_repository, pushArgs);
}
BranchViewFactory::BranchViewFactory()
{
setDisplayName(tr("Git Branches"));