Commit 9654df9f authored by Andre Hartmann's avatar Andre Hartmann Committed by André Hartmann
Browse files

Git: Allow direct push after commit



Git commit dialog: Added a drop-down menu to the commit button to
execute "git push" or open the "Push to Gerrit" dialog directly after
a commit or amend.

Task-number: QTCREATORBUG-8854
Change-Id: I00ff8f816d1768e0cdaf6929126b55826788e578
Reviewed-by: default avatarPetar Perisin <petar.perisin@gmail.com>
Reviewed-by: Orgad Shaneh's avatarOrgad Shaneh <orgads@gmail.com>
parent 02825b58
...@@ -53,6 +53,8 @@ void GitSubmitEditorPanelData::clear() ...@@ -53,6 +53,8 @@ void GitSubmitEditorPanelData::clear()
author.clear(); author.clear();
email.clear(); email.clear();
bypassHooks = false; bypassHooks = false;
pushAction = CommitOnly;
hasRemotes = false;
} }
QString GitSubmitEditorPanelData::authorString() const QString GitSubmitEditorPanelData::authorString() const
...@@ -72,7 +74,8 @@ QString GitSubmitEditorPanelData::authorString() const ...@@ -72,7 +74,8 @@ QString GitSubmitEditorPanelData::authorString() const
QDebug operator<<(QDebug d, const GitSubmitEditorPanelData &data) QDebug operator<<(QDebug d, const GitSubmitEditorPanelData &data)
{ {
d.nospace() << " author:" << data.author << " email: " << data.email d.nospace() << " author:" << data.author << " email: " << data.email
<< " bypass hooks: " << data.bypassHooks; << " bypass hooks: " << data.bypassHooks
<< " action after commit " << data.pushAction;
return d; return d;
} }
......
...@@ -52,6 +52,12 @@ struct GitSubmitEditorPanelInfo ...@@ -52,6 +52,12 @@ struct GitSubmitEditorPanelInfo
QDebug operator<<(QDebug d, const GitSubmitEditorPanelInfo &); QDebug operator<<(QDebug d, const GitSubmitEditorPanelInfo &);
enum PushAction {
CommitOnly,
CommitAndPush,
CommitAndPushToGerrit
};
struct GitSubmitEditorPanelData struct GitSubmitEditorPanelData
{ {
void clear(); void clear();
...@@ -61,6 +67,8 @@ struct GitSubmitEditorPanelData ...@@ -61,6 +67,8 @@ struct GitSubmitEditorPanelData
QString author; QString author;
QString email; QString email;
bool bypassHooks; bool bypassHooks;
PushAction pushAction;
bool hasRemotes;
}; };
QDebug operator<<(QDebug d, const GitSubmitEditorPanelData &); QDebug operator<<(QDebug d, const GitSubmitEditorPanelData &);
......
...@@ -308,10 +308,8 @@ void GerritPlugin::addToLocator(Locator::CommandLocator *locator) ...@@ -308,10 +308,8 @@ void GerritPlugin::addToLocator(Locator::CommandLocator *locator)
locator->appendCommand(m_pushToGerritPair.second); locator->appendCommand(m_pushToGerritPair.second);
} }
void GerritPlugin::push() void GerritPlugin::push(const QString &topLevel)
{ {
const QString topLevel = Git::Internal::GitPlugin::instance()->currentState().topLevel();
// QScopedPointer is required to delete the dialog when leaving the function // QScopedPointer is required to delete the dialog when leaving the function
GerritPushDialog dialog(topLevel, m_reviewers, ICore::mainWindow()); GerritPushDialog dialog(topLevel, m_reviewers, ICore::mainWindow());
...@@ -387,6 +385,11 @@ void GerritPlugin::openView() ...@@ -387,6 +385,11 @@ void GerritPlugin::openView()
m_dialog.data()->raise(); m_dialog.data()->raise();
} }
void GerritPlugin::push()
{
push(Git::Internal::GitPlugin::instance()->currentState().topLevel());
}
QString GerritPlugin::gitBinary() QString GerritPlugin::gitBinary()
{ {
bool ok; bool ok;
......
...@@ -67,6 +67,7 @@ public: ...@@ -67,6 +67,7 @@ public:
static QString gitBinary(); static QString gitBinary();
static QString branch(const QString &repository); static QString branch(const QString &repository);
void addToLocator(Locator::CommandLocator *locator); void addToLocator(Locator::CommandLocator *locator);
void push(const QString &topLevel);
public slots: public slots:
void fetchDisplay(const QSharedPointer<Gerrit::Internal::GerritChange> &change); void fetchDisplay(const QSharedPointer<Gerrit::Internal::GerritChange> &change);
......
...@@ -3044,6 +3044,8 @@ bool GitClient::getCommitData(const QString &workingDirectory, ...@@ -3044,6 +3044,8 @@ bool GitClient::getCommitData(const QString &workingDirectory,
case FixupCommit: case FixupCommit:
break; break;
} }
commitData.panelData.hasRemotes = !synchronousRemotesList(repoDirectory).isEmpty();
return true; return true;
} }
......
...@@ -1121,6 +1121,14 @@ bool GitPlugin::submitEditorAboutToClose() ...@@ -1121,6 +1121,14 @@ bool GitPlugin::submitEditorAboutToClose()
m_gitClient->continueCommandIfNeeded(m_submitRepository); m_gitClient->continueCommandIfNeeded(m_submitRepository);
} }
} }
if (m_gitClient->checkCommandInProgress(m_submitRepository) == GitClient::NoCommand) {
if (editor->panelData().pushAction == CommitAndPush)
m_gitClient->push(m_submitRepository);
else if (editor->panelData().pushAction == CommitAndPushToGerrit)
connect(editor, SIGNAL(destroyed()), this, SLOT(delayedPushToGerrit()));
}
return closeEditor; return closeEditor;
} }
...@@ -1445,6 +1453,11 @@ void GitPlugin::updateContinueAndAbortCommands() ...@@ -1445,6 +1453,11 @@ void GitPlugin::updateContinueAndAbortCommands()
} }
} }
void GitPlugin::delayedPushToGerrit()
{
m_gerritPlugin->push(m_submitRepository);
}
void GitPlugin::updateBranches(const QString &repository) void GitPlugin::updateBranches(const QString &repository)
{ {
if (m_branchDialog && m_branchDialog->isVisible()) if (m_branchDialog && m_branchDialog->isVisible())
......
...@@ -146,6 +146,7 @@ private slots: ...@@ -146,6 +146,7 @@ private slots:
void startMergeTool(); void startMergeTool();
void continueOrAbortCommand(); void continueOrAbortCommand();
void updateContinueAndAbortCommands(); void updateContinueAndAbortCommands();
void delayedPushToGerrit();
#ifdef WITH_TESTS #ifdef WITH_TESTS
void testStatusParsing_data(); void testStatusParsing_data();
......
...@@ -39,6 +39,7 @@ ...@@ -39,6 +39,7 @@
#include <QGroupBox> #include <QGroupBox>
#include <QRegExp> #include <QRegExp>
#include <QVBoxLayout> #include <QVBoxLayout>
#include <QMenu>
namespace Git { namespace Git {
namespace Internal { namespace Internal {
...@@ -46,6 +47,7 @@ namespace Internal { ...@@ -46,6 +47,7 @@ namespace Internal {
// ------------------ // ------------------
GitSubmitEditorWidget::GitSubmitEditorWidget(QWidget *parent) : GitSubmitEditorWidget::GitSubmitEditorWidget(QWidget *parent) :
VcsBase::SubmitEditorWidget(parent), VcsBase::SubmitEditorWidget(parent),
m_pushAction(CommitOnly),
m_gitSubmitPanel(new QWidget), m_gitSubmitPanel(new QWidget),
m_logChangeWidget(0), m_logChangeWidget(0),
m_hasUnmerged(false), m_hasUnmerged(false),
...@@ -105,6 +107,14 @@ void GitSubmitEditorWidget::initialize(CommitType commitType, ...@@ -105,6 +107,14 @@ void GitSubmitEditorWidget::initialize(CommitType commitType,
insertTopWidget(m_gitSubmitPanel); insertTopWidget(m_gitSubmitPanel);
setPanelData(data); setPanelData(data);
setPanelInfo(info); setPanelInfo(info);
if (data.hasRemotes && commitType != FixupCommit) {
QMenu *menu = new QMenu(this);
menu->addAction(tr("Commit only"), this, SLOT(commitOnlySlot()));
menu->addAction(tr("Commit and Push"), this, SLOT(commitAndPushSlot()));
menu->addAction(tr("Commit and Push to Gerrit"), this, SLOT(commitAndPushToGerritSlot()));
addSubmitButtonMenu(menu);
}
} }
void GitSubmitEditorWidget::refreshLog(const QString &repository) void GitSubmitEditorWidget::refreshLog(const QString &repository)
...@@ -119,6 +129,7 @@ GitSubmitEditorPanelData GitSubmitEditorWidget::panelData() const ...@@ -119,6 +129,7 @@ GitSubmitEditorPanelData GitSubmitEditorWidget::panelData() const
rc.author = m_gitSubmitPanelUi.authorLineEdit->text(); rc.author = m_gitSubmitPanelUi.authorLineEdit->text();
rc.email = m_gitSubmitPanelUi.emailLineEdit->text(); rc.email = m_gitSubmitPanelUi.emailLineEdit->text();
rc.bypassHooks = m_gitSubmitPanelUi.bypassHooksCheckBox->isChecked(); rc.bypassHooks = m_gitSubmitPanelUi.bypassHooksCheckBox->isChecked();
rc.pushAction = m_pushAction;
return rc; return rc;
} }
...@@ -158,6 +169,16 @@ QString GitSubmitEditorWidget::cleanupDescription(const QString &input) const ...@@ -158,6 +169,16 @@ QString GitSubmitEditorWidget::cleanupDescription(const QString &input) const
} }
QString GitSubmitEditorWidget::commitName() const
{
if (m_pushAction == CommitAndPush)
return tr("Commit and Push");
else if (m_pushAction == CommitAndPushToGerrit)
return tr("Commit and Push to Gerrit");
return tr("Commit");
}
void GitSubmitEditorWidget::authorInformationChanged() void GitSubmitEditorWidget::authorInformationChanged()
{ {
bool bothEmpty = m_gitSubmitPanelUi.authorLineEdit->text().isEmpty() && bool bothEmpty = m_gitSubmitPanelUi.authorLineEdit->text().isEmpty() &&
...@@ -171,6 +192,24 @@ void GitSubmitEditorWidget::authorInformationChanged() ...@@ -171,6 +192,24 @@ void GitSubmitEditorWidget::authorInformationChanged()
updateSubmitAction(); updateSubmitAction();
} }
void GitSubmitEditorWidget::commitOnlySlot()
{
m_pushAction = CommitOnly;
updateSubmitAction();
}
void GitSubmitEditorWidget::commitAndPushSlot()
{
m_pushAction = CommitAndPush;
updateSubmitAction();
}
void GitSubmitEditorWidget::commitAndPushToGerritSlot()
{
m_pushAction = CommitAndPushToGerrit;
updateSubmitAction();
}
bool GitSubmitEditorWidget::emailIsValid() const bool GitSubmitEditorWidget::emailIsValid() const
{ {
int pos = m_gitSubmitPanelUi.emailLineEdit->cursorPosition(); int pos = m_gitSubmitPanelUi.emailLineEdit->cursorPosition();
......
...@@ -32,6 +32,7 @@ ...@@ -32,6 +32,7 @@
#include "ui_gitsubmitpanel.h" #include "ui_gitsubmitpanel.h"
#include "gitsettings.h" #include "gitsettings.h"
#include "commitdata.h"
#include <texteditor/syntaxhighlighter.h> #include <texteditor/syntaxhighlighter.h>
#include <vcsbase/submiteditorwidget.h> #include <vcsbase/submiteditorwidget.h>
...@@ -77,18 +78,23 @@ public: ...@@ -77,18 +78,23 @@ public:
protected: protected:
bool canSubmit() const; bool canSubmit() const;
QString cleanupDescription(const QString &) const; QString cleanupDescription(const QString &) const;
QString commitName() const;
signals: signals:
void show(const QString &commit); void show(const QString &commit);
private slots: private slots:
void authorInformationChanged(); void authorInformationChanged();
void commitOnlySlot();
void commitAndPushSlot();
void commitAndPushToGerritSlot();
private: private:
bool emailIsValid() const; bool emailIsValid() const;
void setPanelData(const GitSubmitEditorPanelData &data); void setPanelData(const GitSubmitEditorPanelData &data);
void setPanelInfo(const GitSubmitEditorPanelInfo &info); void setPanelInfo(const GitSubmitEditorPanelInfo &info);
PushAction m_pushAction;
QWidget *m_gitSubmitPanel; QWidget *m_gitSubmitPanel;
LogChangeWidget *m_logChangeWidget; LogChangeWidget *m_logChangeWidget;
Ui::GitSubmitPanel m_gitSubmitPanelUi; Ui::GitSubmitPanel m_gitSubmitPanelUi;
......
...@@ -37,7 +37,6 @@ ...@@ -37,7 +37,6 @@
#include <QTimer> #include <QTimer>
#include <QScopedPointer> #include <QScopedPointer>
#include <QPushButton>
#include <QMenu> #include <QMenu>
#include <QHBoxLayout> #include <QHBoxLayout>
#include <QToolButton> #include <QToolButton>
...@@ -75,7 +74,7 @@ namespace VcsBase { ...@@ -75,7 +74,7 @@ namespace VcsBase {
// QActionPushButton: A push button tied to an action // QActionPushButton: A push button tied to an action
// (similar to a QToolButton) // (similar to a QToolButton)
class QActionPushButton : public QPushButton class QActionPushButton : public QToolButton
{ {
Q_OBJECT Q_OBJECT
public: public:
...@@ -86,8 +85,11 @@ private slots: ...@@ -86,8 +85,11 @@ private slots:
}; };
QActionPushButton::QActionPushButton(QAction *a) : QActionPushButton::QActionPushButton(QAction *a) :
QPushButton(a->icon(), a->text()) QToolButton()
{ {
setIcon(a->icon());
setText(a->text());
setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
connect(a, SIGNAL(changed()), this, SLOT(actionChanged())); connect(a, SIGNAL(changed()), this, SLOT(actionChanged()));
connect(this, SIGNAL(clicked()), a, SLOT(trigger())); connect(this, SIGNAL(clicked()), a, SLOT(trigger()));
setEnabled(a->isEnabled()); setEnabled(a->isEnabled());
...@@ -153,6 +155,8 @@ struct SubmitEditorWidgetPrivate ...@@ -153,6 +155,8 @@ struct SubmitEditorWidgetPrivate
bool m_commitEnabled; bool m_commitEnabled;
bool m_ignoreChange; bool m_ignoreChange;
bool m_descriptionMandatory; bool m_descriptionMandatory;
QActionPushButton *m_submitButton;
}; };
SubmitEditorWidgetPrivate::SubmitEditorWidgetPrivate() : SubmitEditorWidgetPrivate::SubmitEditorWidgetPrivate() :
...@@ -164,7 +168,8 @@ SubmitEditorWidgetPrivate::SubmitEditorWidgetPrivate() : ...@@ -164,7 +168,8 @@ SubmitEditorWidgetPrivate::SubmitEditorWidgetPrivate() :
m_lineWidth(defaultLineWidth), m_lineWidth(defaultLineWidth),
m_commitEnabled(false), m_commitEnabled(false),
m_ignoreChange(false), m_ignoreChange(false),
m_descriptionMandatory(true) m_descriptionMandatory(true),
m_submitButton(0)
{ {
} }
...@@ -229,7 +234,8 @@ void SubmitEditorWidget::registerActions(QAction *editorUndoAction, QAction *edi ...@@ -229,7 +234,8 @@ void SubmitEditorWidget::registerActions(QAction *editorUndoAction, QAction *edi
if (!actionSlotHelper) if (!actionSlotHelper)
actionSlotHelper = new QActionSetTextSlotHelper(submitAction); actionSlotHelper = new QActionSetTextSlotHelper(submitAction);
connect(this, SIGNAL(submitActionTextChanged(QString)), actionSlotHelper, SLOT(setText(QString))); connect(this, SIGNAL(submitActionTextChanged(QString)), actionSlotHelper, SLOT(setText(QString)));
d->m_ui.buttonLayout->addWidget(new QActionPushButton(submitAction)); d->m_submitButton = new QActionPushButton(submitAction);
d->m_ui.buttonLayout->addWidget(d->m_submitButton);
if (!d->m_submitShortcut) if (!d->m_submitShortcut)
d->m_submitShortcut = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_Return), this); d->m_submitShortcut = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_Return), this);
connect(d->m_submitShortcut, SIGNAL(activated()), submitAction, SLOT(trigger())); connect(d->m_submitShortcut, SIGNAL(activated()), submitAction, SLOT(trigger()));
...@@ -523,6 +529,11 @@ void SubmitEditorWidget::insertTopWidget(QWidget *w) ...@@ -523,6 +529,11 @@ void SubmitEditorWidget::insertTopWidget(QWidget *w)
d->m_ui.vboxLayout->insertWidget(0, w); d->m_ui.vboxLayout->insertWidget(0, w);
} }
void SubmitEditorWidget::addSubmitButtonMenu(QMenu *menu)
{
d->m_submitButton->setMenu(menu);
}
void SubmitEditorWidget::hideDescription() void SubmitEditorWidget::hideDescription()
{ {
d->m_ui.descriptionBox->hide(); d->m_ui.descriptionBox->hide();
......
...@@ -121,6 +121,7 @@ protected: ...@@ -121,6 +121,7 @@ protected:
virtual QString cleanupDescription(const QString &) const; virtual QString cleanupDescription(const QString &) const;
virtual QString commitName() const; virtual QString commitName() const;
void insertTopWidget(QWidget *w); void insertTopWidget(QWidget *w);
void addSubmitButtonMenu(QMenu *menu);
void hideDescription(); void hideDescription();
protected slots: protected slots:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment