diff --git a/src/plugins/git/gerrit/gerritpushdialog.cpp b/src/plugins/git/gerrit/gerritpushdialog.cpp index 1c42c67b88d..88893d5bdd1 100644 --- a/src/plugins/git/gerrit/gerritpushdialog.cpp +++ b/src/plugins/git/gerrit/gerritpushdialog.cpp @@ -150,6 +150,9 @@ GerritPushDialog::GerritPushDialog(const QString &workingDir, const QString &rev connect(m_ui->targetBranchComboBox, static_cast(&QComboBox::currentIndexChanged), this, &GerritPushDialog::setChangeRange); + connect(m_ui->targetBranchComboBox, &QComboBox::currentTextChanged, + this, &GerritPushDialog::validate); + updateCommits(m_ui->localBranchComboBox->currentIndex()); setRemoteBranches(); @@ -223,8 +226,17 @@ void GerritPushDialog::setRemoteBranches(bool includeOld) const QString remoteName = selectedRemoteName(); if (!m_remoteBranches.contains(remoteName)) { - foreach (const QString &branch, GitPlugin::client()->synchronousRepositoryBranches(remoteName, m_workingDir)) + const QStringList remoteBranches = + GitPlugin::client()->synchronousRepositoryBranches(remoteName, m_workingDir); + foreach (const QString &branch, remoteBranches) m_remoteBranches.insertMulti(remoteName, qMakePair(branch, QDate())); + if (remoteBranches.isEmpty()) { + m_ui->targetBranchComboBox->setEditable(true); + m_ui->targetBranchComboBox->setToolTip( + tr("No remote branches found. This is probably the initial commit.")); + if (QLineEdit *lineEdit = m_ui->targetBranchComboBox->lineEdit()) + lineEdit->setPlaceholderText(tr("Branch name")); + } } int i = 0; @@ -250,8 +262,7 @@ void GerritPushDialog::setRemoteBranches(bool includeOld) void GerritPushDialog::updateCommits(int index) { const QString branch = m_ui->localBranchComboBox->itemText(index); - const bool hasLocalCommits = m_ui->commitView->init(m_workingDir, branch, - LogChangeWidget::Silent); + m_hasLocalCommits = m_ui->commitView->init(m_workingDir, branch, LogChangeWidget::Silent); const QString remoteBranch = determineRemoteBranch(branch); if (!remoteBranch.isEmpty()) { @@ -265,8 +276,13 @@ void GerritPushDialog::updateCommits(int index) else setRemoteBranches(); } + validate(); +} - m_ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(hasLocalCommits); +void GerritPushDialog::validate() +{ + const bool valid = m_hasLocalCommits && !selectedRemoteBranchName().isEmpty(); + m_ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(valid); } QString GerritPushDialog::selectedRemoteName() const diff --git a/src/plugins/git/gerrit/gerritpushdialog.h b/src/plugins/git/gerrit/gerritpushdialog.h index ace926fdc55..c4ffb7da6b0 100644 --- a/src/plugins/git/gerrit/gerritpushdialog.h +++ b/src/plugins/git/gerrit/gerritpushdialog.h @@ -58,6 +58,7 @@ private: void setChangeRange(); void setRemoteBranches(bool includeOld = false); void updateCommits(int index); + void validate(); typedef QPair BranchDate; typedef QMultiMap RemoteBranchesMap; @@ -70,6 +71,7 @@ private: Ui::GerritPushDialog *m_ui; RemoteBranchesMap m_remoteBranches; bool m_isValid = false; + bool m_hasLocalCommits = false; };