Commit fe1f7e4b authored by Petar Perisin's avatar Petar Perisin
Browse files

Gerrit: Added pushToGerrit dialog



Change-Id: Ic16eae2def11343ef7be5ce8378d24b5fd11a386
Reviewed-by: default avatarPetar Perisin <petar.perisin@gmail.com>
Reviewed-by: Orgad Shaneh's avatarOrgad Shaneh <orgads@gmail.com>
Reviewed-by: default avatarFriedemann Kleint <Friedemann.Kleint@digia.com>
Reviewed-by: default avatarTobias Hunger <tobias.hunger@digia.com>
parent 83d51b26
......@@ -4,10 +4,14 @@ SOURCES += $$PWD/gerritdialog.cpp \
$$PWD/gerritmodel.cpp \
$$PWD/gerritparameters.cpp \
$$PWD/gerritplugin.cpp \
$$PWD/gerritoptionspage.cpp
$$PWD/gerritoptionspage.cpp \
$$PWD/gerritpushdialog.cpp
HEADERS += $$PWD/gerritdialog.h \
$$PWD/gerritmodel.h \
$$PWD/gerritparameters.h \
$$PWD/gerritplugin.h \
$$PWD/gerritoptionspage.h
$$PWD/gerritoptionspage.h \
$$PWD/gerritpushdialog.h
FORMS += $$PWD/gerritpushdialog.ui
......@@ -32,6 +32,7 @@
#include "gerritdialog.h"
#include "gerritmodel.h"
#include "gerritoptionspage.h"
#include "gerritpushdialog.h"
#include "../gitplugin.h"
#include "../gitclient.h"
......@@ -50,6 +51,7 @@
#include <coreplugin/actionmanager/actioncontainer.h>
#include <coreplugin/actionmanager/command.h>
#include <coreplugin/editormanager/editormanager.h>
#include <locator/commandlocator.h>
#include <vcsbase/vcsbaseoutputwindow.h>
......@@ -70,6 +72,7 @@ enum { debug = 0 };
namespace Gerrit {
namespace Constants {
const char GERRIT_OPEN_VIEW[] = "Gerrit.OpenView";
const char GERRIT_PUSH[] = "Gerrit.Push";
}
namespace Internal {
......@@ -332,10 +335,59 @@ bool GerritPlugin::initialize(Core::ActionContainer *ac)
connect(openViewAction, SIGNAL(triggered()), this, SLOT(openView()));
ac->addAction(command);
QAction *pushAction = new QAction(tr("Push to Gerrit..."), this);
Core::Command *pushCommand =
Core::ActionManager::registerAction(pushAction, Constants::GERRIT_PUSH,
Core::Context(Core::Constants::C_GLOBAL));
connect(pushAction, SIGNAL(triggered()), this, SLOT(push()));
ac->addAction(pushCommand);
m_pushToGerritPair = ActionCommandPair(pushAction, pushCommand);
Git::Internal::GitPlugin::instance()->addAutoReleasedObject(new GerritOptionsPage(m_parameters));
return true;
}
void GerritPlugin::updateActions(bool hasTopLevel)
{
m_pushToGerritPair.first->setEnabled(hasTopLevel);
}
void GerritPlugin::addToLocator(Locator::CommandLocator *locator)
{
locator->appendCommand(m_pushToGerritPair.second);
}
void GerritPlugin::push()
{
const QString topLevel = Git::Internal::GitPlugin::instance()->currentState().topLevel();
QPointer<GerritPushDialog> dialog = new GerritPushDialog(topLevel, Core::ICore::mainWindow());
if (!dialog->localChangesFound()) {
QMessageBox::critical(Core::ICore::mainWindow(), tr("No Local Changes"),
tr("Change from HEAD appears to be in remote branch already! Aborting."));
return;
}
if (dialog->exec() == QDialog::Rejected)
return;
if (dialog.isNull())
return;
QStringList args;
args << dialog->selectedRemoteName();
args << QLatin1String("HEAD:refs/") + dialog->selectedPushType() +
QLatin1Char('/') + dialog->selectedRemoteBranchName();
Git::Internal::GitPlugin::instance()->gitClient()->synchronousPush(topLevel, args);
delete dialog;
}
// Open or raise the Gerrit dialog window.
void GerritPlugin::openView()
{
......
......@@ -33,9 +33,19 @@
#include <QObject>
#include <QPointer>
#include <QSharedPointer>
#include <QPair>
QT_BEGIN_NAMESPACE
class QAction;
QT_END_NAMESPACE
namespace Core {
class ActionContainer;
class Command;
}
namespace Locator {
class CommandLocator;
}
namespace Gerrit {
......@@ -45,6 +55,8 @@ class GerritChange;
class GerritParameters;
class GerritDialog;
typedef QPair<QAction *, Core::Command* > ActionCommandPair;
class GerritPlugin : public QObject
{
Q_OBJECT
......@@ -56,11 +68,13 @@ public:
static QString gitBinary();
static QString branch(const QString &repository);
void addToLocator(Locator::CommandLocator *locator);
public slots:
void fetchDisplay(const QSharedPointer<Gerrit::Internal::GerritChange> &change);
void fetchApply(const QSharedPointer<Gerrit::Internal::GerritChange> &change);
void fetchCheckout(const QSharedPointer<Gerrit::Internal::GerritChange> &change);
void updateActions(bool hasTopLevel);
signals:
void fetchStarted(const QSharedPointer<Gerrit::Internal::GerritChange> &change);
......@@ -68,6 +82,7 @@ signals:
private slots:
void openView();
void push();
private:
QString findLocalRepository(QString project, const QString &branch) const;
......@@ -75,6 +90,7 @@ private:
QSharedPointer<GerritParameters> m_parameters;
QPointer<GerritDialog> m_dialog;
ActionCommandPair m_pushToGerritPair;
};
} // namespace Internal
......
/****************************************************************************
**
** Copyright (C) 2013 Petar Perisin.
** Contact: petar.perisin@gmail.com
**
** 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 "gerritpushdialog.h"
#include "ui_gerritpushdialog.h"
#include "../gitplugin.h"
#include "../gitclient.h"
#include <coreplugin/icore.h>
#include <QDir>
#include <QMessageBox>
namespace Gerrit {
namespace Internal {
GerritPushDialog::GerritPushDialog(const QString &workingDir, QWidget *parent) :
QDialog(parent),
m_workingDir(workingDir),
m_ui(new Ui::GerritPushDialog),
m_remoteBranches(new QMap<QString,QString>()),
m_localChangesFound(true)
{
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
m_ui->setupUi(this);
m_ui->repositoryLabel->setText(tr("Local Repository: %1").arg(
QDir::toNativeSeparators(workingDir)));
Git::Internal::GitClient *gitClient = Git::Internal::GitPlugin::instance()->gitClient();
QString output;
QString error;
QStringList args;
args << QLatin1String("--no-color") << QLatin1String("--format=%P")
<< QLatin1String("HEAD") << QLatin1String("--not")<< QLatin1String("--remotes");
if (!gitClient->synchronousLog(m_workingDir, args, &output) || output.isEmpty())
reject();
output.chop(1);
if (output.isEmpty()) {
output = QLatin1String("HEAD");
m_localChangesFound = false;
} else {
output = output.mid(output.lastIndexOf(QLatin1Char('\n')) + 1);
}
args.clear();
args << QLatin1String("--remotes") << QLatin1String("--contains") << output;
if (!gitClient->synchronousBranchCmd(m_workingDir, args, &output, &error))
reject();
QString head = QLatin1String("/HEAD");
QStringList refs = output.split(QLatin1Char('\n'));
foreach (const QString &reference, refs) {
if (reference.contains(head) || reference.isEmpty())
continue;
m_suggestedRemoteName = reference.left(reference.indexOf(QLatin1Char('/'))).trimmed();
m_suggestedRemoteBranch = reference.mid(reference.indexOf(QLatin1Char('/')) + 1).trimmed();
break;
}
output.clear();
error.clear();
args.clear();
args << QLatin1String("--remotes");
if (!gitClient->synchronousBranchCmd(m_workingDir, args, &output, &error))
reject();
refs.clear();
refs = output.split(QLatin1String("\n"));
foreach (const QString &reference, refs) {
if (reference.contains(head) || reference.isEmpty())
continue;
int refBranchIndex = reference.indexOf(QLatin1Char('/'));
m_remoteBranches->insertMulti(reference.left(refBranchIndex).trimmed(),
reference.mid(refBranchIndex + 1).trimmed());
}
int currIndex = 0;
QStringList remotes = m_remoteBranches->keys();
remotes.removeDuplicates();
foreach (const QString &remote, remotes) {
m_ui->remoteComboBox->addItem(remote);
if (remote == m_suggestedRemoteName)
m_ui->remoteComboBox->setCurrentIndex(currIndex);
++currIndex;
}
if (m_ui->remoteComboBox->count() < 1)
reject();
m_ui->remoteComboBox->setEnabled(m_ui->remoteComboBox->count() != 1);
connect(m_ui->remoteComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(setRemoteBranches()));
connect(m_ui->branchComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(setChangeRange()));
setRemoteBranches();
}
GerritPushDialog::~GerritPushDialog()
{
delete m_ui;
delete m_remoteBranches;
}
QString GerritPushDialog::calculateChangeRange()
{
QString remote = selectedRemoteName();
remote += QLatin1Char('/');
remote += selectedRemoteBranchName();
QStringList args(remote + QLatin1String("..HEAD"));
args << QLatin1String("--count");
QString number;
if (!Git::Internal::GitPlugin::instance()->gitClient()->
synchronousRevListCmd(m_workingDir, args, &number))
reject();
number.chop(1);
return number;
}
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;
}
void GerritPushDialog::setRemoteBranches()
{
m_ui->branchComboBox->clear();
QMap<QString, QString>::const_iterator it;
int i = 0;
for (it = m_remoteBranches->constBegin(); it != m_remoteBranches->constEnd(); ++it) {
if (it.key() == selectedRemoteName()) {
m_ui->branchComboBox->addItem(it.value());
if (it.value() == m_suggestedRemoteBranch)
m_ui->branchComboBox->setCurrentIndex(i);
++i;
}
}
setChangeRange();
}
QString GerritPushDialog::selectedRemoteName() const
{
return m_ui->remoteComboBox->currentText();
}
QString GerritPushDialog::selectedRemoteBranchName() const
{
return m_ui->branchComboBox->currentText();
}
QString GerritPushDialog::selectedPushType() const
{
return m_ui->publicRadioButton->isChecked() ? QLatin1String("for") : QLatin1String("draft");
}
} // namespace Internal
} // namespace Gerrit
/****************************************************************************
**
** Copyright (C) 2013 Petar Perisin.
** Contact: petar.perisin@gmail.com
**
** 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 GERRITPUSHDIALOG_H
#define GERRITPUSHDIALOG_H
#include <QDialog>
namespace Gerrit {
namespace Internal {
namespace Ui {
class GerritPushDialog;
}
class GerritPushDialog : public QDialog
{
Q_OBJECT
public:
GerritPushDialog(const QString &workingDir, QWidget *parent = 0);
~GerritPushDialog();
QString selectedRemoteName() const;
QString selectedRemoteBranchName() const;
QString selectedPushType() const;
bool localChangesFound() const;
private slots:
void setChangeRange();
void setRemoteBranches();
private:
QString calculateChangeRange();
QString m_workingDir;
QString m_suggestedRemoteName;
QString m_suggestedRemoteBranch;
Ui::GerritPushDialog *m_ui;
QMap<QString,QString> *m_remoteBranches;
bool m_localChangesFound;
};
} // namespace Internal
} // namespace Gerrit
#endif // GERRITPUSHDIALOG_H
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Gerrit::Internal::GerritPushDialog</class>
<widget class="QDialog" name="Gerrit::Internal::GerritPushDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>306</width>
<height>304</height>
</rect>
</property>
<property name="windowTitle">
<string>Push to Gerrit</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="leftMargin">
<number>10</number>
</property>
<property name="topMargin">
<number>3</number>
</property>
<property name="rightMargin">
<number>3</number>
</property>
<property name="bottomMargin">
<number>3</number>
</property>
<item>
<widget class="QLabel" name="repositoryLabel">
<property name="text">
<string>Local Repository:</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QGroupBox" name="pushTypeGroupBox">
<property name="title">
<string>Push Type:</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QRadioButton" name="publicRadioButton">
<property name="text">
<string>Public</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="draftRadioButton">
<property name="text">
<string>Draft</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="remoteGroupBox">
<property name="title">
<string>Remote Branch:</string>
</property>
<layout class="QFormLayout" name="formLayout">
<item row="1" column="1">
<widget class="QComboBox" name="remoteComboBox"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="remoteLabel">
<property name="text">
<string>Remote Name:</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="branchLabel">
<property name="text">
<string>Branch Name:</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QComboBox" name="branchComboBox"/>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QLabel" name="infoLabel">
<property name="text">
<string>Number of commits</string>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>Gerrit::Internal::GerritPushDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>227</x>
<y>330</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>Gerrit::Internal::GerritPushDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>295</x>
<y>336</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>
......@@ -107,6 +107,9 @@ QtcPlugin {
"gerritparameters.h",
"gerritplugin.cpp",
"gerritplugin.h",
"gerritpushdialog.cpp",
"gerritpushdialog.h",
"gerritpushdialog.ui",
]
}
}
......@@ -1121,6 +1121,29 @@ static inline bool splitCommitParents(cons