summaryrefslogtreecommitdiff
path: root/src/plugins
diff options
context:
space:
mode:
authorOrgad Shaneh <orgad.shaneh@audiocodes.com>2014-02-08 21:36:06 +0200
committerOrgad Shaneh <orgads@gmail.com>2014-02-11 12:06:29 +0100
commit1ed9f6bbca1a8e7908b685f03f3100c6ebcaddb1 (patch)
treebbead2083a8563bc16e227d20d9efff93077b949 /src/plugins
parent292e4599aae1092abc130ef4603e9fcdbfb2b0fd (diff)
downloadqt-creator-1ed9f6bbca1a8e7908b685f03f3100c6ebcaddb1.tar.gz
Git: Enable local branch selection in Push to Gerrit
Show dialog even if there are no local commits in current branch Change-Id: I11e0c6505981712df51bb33694a6cba9704d7324 Reviewed-by: Tobias Hunger <tobias.hunger@digia.com>
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/git/gerrit/branchcombobox.cpp69
-rw-r--r--src/plugins/git/gerrit/branchcombobox.h59
-rw-r--r--src/plugins/git/gerrit/gerrit.pri6
-rw-r--r--src/plugins/git/gerrit/gerritplugin.cpp3
-rw-r--r--src/plugins/git/gerrit/gerritpushdialog.cpp42
-rw-r--r--src/plugins/git/gerrit/gerritpushdialog.h5
-rw-r--r--src/plugins/git/gerrit/gerritpushdialog.ui32
-rw-r--r--src/plugins/git/git.qbs2
8 files changed, 189 insertions, 29 deletions
diff --git a/src/plugins/git/gerrit/branchcombobox.cpp b/src/plugins/git/gerrit/branchcombobox.cpp
new file mode 100644
index 0000000000..9e583bb15d
--- /dev/null
+++ b/src/plugins/git/gerrit/branchcombobox.cpp
@@ -0,0 +1,69 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Orgad Shaneh <orgads@gmail.com>.
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of Qt Creator.
+**
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+****************************************************************************/
+
+#include "branchcombobox.h"
+#include "../gitplugin.h"
+#include "../gitclient.h"
+
+using namespace Git::Internal;
+using namespace Gerrit::Internal;
+
+BranchComboBox::BranchComboBox(QWidget *parent) :
+ QComboBox(parent),
+ m_detached(false)
+{
+ m_client = GitPlugin::instance()->gitClient();
+}
+
+void BranchComboBox::init(const QString &repository)
+{
+ m_repository = repository;
+ QString currentBranch = m_client->synchronousCurrentLocalBranch(repository);
+ if (currentBranch.isEmpty()) {
+ m_detached = true;
+ currentBranch = QLatin1String("HEAD");
+ addItem(currentBranch);
+ }
+ QString output;
+ const QString branchPrefix(QLatin1String("refs/heads/"));
+ QStringList args;
+ args << QLatin1String("--format=%(refname)") << branchPrefix;
+ if (!m_client->synchronousForEachRefCmd(m_repository, args, &output))
+ return;
+ QStringList branches = output.trimmed().split(QLatin1Char('\n'));
+ foreach (const QString &ref, branches) {
+ const QString branch = ref.mid(branchPrefix.size());
+ addItem(branch);
+ }
+ if (currentBranch.isEmpty())
+ return;
+ int index = findText(currentBranch);
+ if (index != -1)
+ setCurrentIndex(index);
+}
diff --git a/src/plugins/git/gerrit/branchcombobox.h b/src/plugins/git/gerrit/branchcombobox.h
new file mode 100644
index 0000000000..207bc4b546
--- /dev/null
+++ b/src/plugins/git/gerrit/branchcombobox.h
@@ -0,0 +1,59 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Orgad Shaneh <orgads@gmail.com>.
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of Qt Creator.
+**
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+****************************************************************************/
+
+#ifndef BRANCHCOMBOBOX_H
+#define BRANCHCOMBOBOX_H
+
+#include <QComboBox>
+
+namespace Git {
+namespace Internal {
+class GitClient;
+}
+}
+
+namespace Gerrit {
+namespace Internal {
+
+class BranchComboBox : public QComboBox
+{
+public:
+ BranchComboBox(QWidget *parent = 0);
+ void init(const QString &repository);
+
+private:
+ Git::Internal::GitClient *m_client;
+ QString m_repository;
+ bool m_detached;
+};
+
+} // namespace Internal
+} // namespace Gerrit
+
+#endif // BRANCHCOMBOBOX_H
diff --git a/src/plugins/git/gerrit/gerrit.pri b/src/plugins/git/gerrit/gerrit.pri
index 617cd941bf..c13f9e210b 100644
--- a/src/plugins/git/gerrit/gerrit.pri
+++ b/src/plugins/git/gerrit/gerrit.pri
@@ -3,13 +3,15 @@ SOURCES += $$PWD/gerritdialog.cpp \
$$PWD/gerritparameters.cpp \
$$PWD/gerritplugin.cpp \
$$PWD/gerritoptionspage.cpp \
- $$PWD/gerritpushdialog.cpp
+ $$PWD/gerritpushdialog.cpp \
+ $$PWD/branchcombobox.cpp
HEADERS += $$PWD/gerritdialog.h \
$$PWD/gerritmodel.h \
$$PWD/gerritparameters.h \
$$PWD/gerritplugin.h \
$$PWD/gerritoptionspage.h \
- $$PWD/gerritpushdialog.h
+ $$PWD/gerritpushdialog.h \
+ $$PWD/branchcombobox.h
FORMS += $$PWD/gerritpushdialog.ui
diff --git a/src/plugins/git/gerrit/gerritplugin.cpp b/src/plugins/git/gerrit/gerritplugin.cpp
index 27fe009d6a..f51adbb511 100644
--- a/src/plugins/git/gerrit/gerritplugin.cpp
+++ b/src/plugins/git/gerrit/gerritplugin.cpp
@@ -313,9 +313,6 @@ void GerritPlugin::push(const QString &topLevel)
// QScopedPointer is required to delete the dialog when leaving the function
GerritPushDialog dialog(topLevel, m_reviewers, ICore::mainWindow());
- if (!dialog.localChangesFound())
- return;
-
if (!dialog.valid()) {
QMessageBox::warning(ICore::mainWindow(), tr("Initialization Failed"),
tr("Failed to initialize dialog. Aborting."));
diff --git a/src/plugins/git/gerrit/gerritpushdialog.cpp b/src/plugins/git/gerrit/gerritpushdialog.cpp
index b9223e9e78..75a8f61d6f 100644
--- a/src/plugins/git/gerrit/gerritpushdialog.cpp
+++ b/src/plugins/git/gerrit/gerritpushdialog.cpp
@@ -29,12 +29,14 @@
#include "gerritpushdialog.h"
#include "ui_gerritpushdialog.h"
+#include "branchcombobox.h"
#include "../gitplugin.h"
#include "../gitclient.h"
#include <QDateTime>
#include <QDir>
+#include <QPushButton>
#include <QRegExpValidator>
using namespace Git::Internal;
@@ -61,7 +63,6 @@ QString GerritPushDialog::determineRemoteBranch()
{
const QString earliestCommit = m_ui->commitView->earliestCommit();
- m_localChangesFound = true;
QString output;
QString error;
QStringList args;
@@ -73,7 +74,11 @@ QString GerritPushDialog::determineRemoteBranch()
const QString head = QLatin1String("/HEAD");
QStringList refs = output.split(QLatin1Char('\n'));
- const QString remoteTrackingBranch = m_client->synchronousTrackingBranch(m_workingDir);
+ QString localBranch = m_ui->localBranchComboBox->currentText();
+ if (localBranch == QLatin1String("HEAD"))
+ localBranch.clear();
+ const QString remoteTrackingBranch = m_client->synchronousTrackingBranch(m_workingDir,
+ localBranch);
QString remoteBranch;
foreach (const QString &reference, refs) {
const QString ref = reference.trimmed();
@@ -139,9 +144,6 @@ GerritPushDialog::GerritPushDialog(const QString &workingDir, const QString &rev
m_ui->repositoryLabel->setText(tr("<b>Local repository:</b> %1").arg(
QDir::toNativeSeparators(workingDir)));
- if (!m_ui->commitView->init(workingDir))
- return;
-
PushItemDelegate *delegate = new PushItemDelegate(m_ui->commitView);
delegate->setParent(this);
@@ -156,12 +158,18 @@ GerritPushDialog::GerritPushDialog(const QString &workingDir, const QString &rev
} else {
connect(m_ui->remoteComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(setRemoteBranches()));
}
+ m_ui->localBranchComboBox->init(workingDir);
+ connect(m_ui->localBranchComboBox, SIGNAL(currentIndexChanged(int)),
+ this, SLOT(updateCommits(int)));
+
connect(m_ui->targetBranchComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(setChangeRange()));
setRemoteBranches();
+
m_ui->reviewersLineEdit->setText(reviewerList);
m_ui->topicLineEdit->setValidator(new QRegExpValidator(QRegExp(QLatin1String("^\\S+$")), this));
+ updateCommits(m_ui->localBranchComboBox->currentIndex());
m_valid = true;
}
@@ -175,13 +183,13 @@ QString GerritPushDialog::selectedCommit() const
return m_ui->commitView->commit();
}
-QString GerritPushDialog::calculateChangeRange()
+QString GerritPushDialog::calculateChangeRange(const QString &branch)
{
QString remote = selectedRemoteName();
remote += QLatin1Char('/');
remote += selectedRemoteBranchName();
- QStringList args(remote + QLatin1String("..HEAD"));
+ QStringList args(remote + QLatin1String("..") + branch);
args << QLatin1String("--count");
QString number;
@@ -202,13 +210,11 @@ void GerritPushDialog::setChangeRange()
QString remote = selectedRemoteName();
remote += QLatin1Char('/');
remote += selectedRemoteBranchName();
- m_ui->infoLabel->setText(tr("Number of commits between HEAD and %1: %2").arg(
- remote, calculateChangeRange()));
-}
-
-bool GerritPushDialog::localChangesFound() const
-{
- return m_localChangesFound;
+ const QString branch = m_ui->localBranchComboBox->currentText();
+ m_ui->infoLabel->setText(tr("Number of commits between %1 and %2: %3")
+ .arg(branch)
+ .arg(remote)
+ .arg(calculateChangeRange(branch)));
}
bool GerritPushDialog::valid() const
@@ -245,6 +251,14 @@ void GerritPushDialog::setRemoteBranches(bool includeOld)
m_ui->targetBranchComboBox->blockSignals(blocked);
}
+void GerritPushDialog::updateCommits(int index)
+{
+ const QString branch = m_ui->localBranchComboBox->itemText(index);
+ const bool hasLocalCommits = m_ui->commitView->init(m_workingDir, branch);
+ m_ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(hasLocalCommits);
+ setChangeRange();
+}
+
QString GerritPushDialog::selectedRemoteName() const
{
return m_ui->remoteComboBox->currentText();
diff --git a/src/plugins/git/gerrit/gerritpushdialog.h b/src/plugins/git/gerrit/gerritpushdialog.h
index df34a28548..27fd99f040 100644
--- a/src/plugins/git/gerrit/gerritpushdialog.h
+++ b/src/plugins/git/gerrit/gerritpushdialog.h
@@ -61,12 +61,12 @@ public:
QString selectedPushType() const;
QString selectedTopic() const;
QString reviewers() const;
- bool localChangesFound() const;
bool valid() const;
private slots:
void setChangeRange();
void setRemoteBranches(bool includeOld = false);
+ void updateCommits(int index);
private:
typedef QPair<QString, QDate> BranchDate;
@@ -74,12 +74,11 @@ private:
QString determineRemoteBranch();
void initRemoteBranches();
- QString calculateChangeRange();
+ QString calculateChangeRange(const QString &branch);
QString m_workingDir;
QString m_suggestedRemoteBranch;
Ui::GerritPushDialog *m_ui;
RemoteBranchesMap m_remoteBranches;
- bool m_localChangesFound;
bool m_valid;
Git::Internal::GitClient *m_client;
};
diff --git a/src/plugins/git/gerrit/gerritpushdialog.ui b/src/plugins/git/gerrit/gerritpushdialog.ui
index 3682c164c4..67994ecf64 100644
--- a/src/plugins/git/gerrit/gerritpushdialog.ui
+++ b/src/plugins/git/gerrit/gerritpushdialog.ui
@@ -47,6 +47,19 @@
<enum>QFormLayout::AllNonFixedFieldsGrow</enum>
</property>
<item row="1" column="0">
+ <widget class="QLabel" name="localBranchLabel">
+ <property name="text">
+ <string>&amp;Local branch:</string>
+ </property>
+ <property name="buddy">
+ <cstring>localBranchComboBox</cstring>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="1">
+ <widget class="BranchComboBox" name="localBranchComboBox"/>
+ </item>
+ <item row="2" column="0">
<widget class="QLabel" name="remoteLabel">
<property name="text">
<string>R&amp;emote:</string>
@@ -56,10 +69,10 @@
</property>
</widget>
</item>
- <item row="1" column="1">
+ <item row="2" column="1">
<widget class="QComboBox" name="remoteComboBox"/>
</item>
- <item row="2" column="0">
+ <item row="3" column="0">
<widget class="QLabel" name="targetBranchLabel">
<property name="text">
<string>Target &amp;branch:</string>
@@ -69,10 +82,10 @@
</property>
</widget>
</item>
- <item row="2" column="1">
+ <item row="3" column="1">
<widget class="QComboBox" name="targetBranchComboBox"/>
</item>
- <item row="3" column="0">
+ <item row="4" column="0">
<widget class="QLabel" name="topicLabel">
<property name="text">
<string>&amp;Topic:</string>
@@ -82,17 +95,17 @@
</property>
</widget>
</item>
- <item row="3" column="1">
+ <item row="4" column="1">
<widget class="QLineEdit" name="topicLineEdit"/>
</item>
- <item row="4" column="0">
+ <item row="5" column="0">
<widget class="QCheckBox" name="draftCheckBox">
<property name="text">
<string>&amp;Draft</string>
</property>
</widget>
</item>
- <item row="5" column="0" colspan="2">
+ <item row="6" column="0" colspan="2">
<widget class="QLabel" name="infoLabel">
<property name="text">
<string>Number of commits</string>
@@ -178,6 +191,11 @@ Partial names can be used if they are unambiguous.</string>
<extends>QTreeView</extends>
<header location="global">git/logchangedialog.h</header>
</customwidget>
+ <customwidget>
+ <class>BranchComboBox</class>
+ <extends>QComboBox</extends>
+ <header location="global">git/gerrit/branchcombobox.h</header>
+ </customwidget>
</customwidgets>
<resources/>
<connections>
diff --git a/src/plugins/git/git.qbs b/src/plugins/git/git.qbs
index bff95c4aca..d10d767062 100644
--- a/src/plugins/git/git.qbs
+++ b/src/plugins/git/git.qbs
@@ -101,6 +101,8 @@ QtcPlugin {
name: "Gerrit"
prefix: "gerrit/"
files: [
+ "branchcombobox.cpp",
+ "branchcombobox.h",
"gerritdialog.cpp",
"gerritdialog.h",
"gerritmodel.cpp",