forked from qt-creator/qt-creator
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: Petar Perisin <petar.perisin@gmail.com> Reviewed-by: Orgad Shaneh <orgads@gmail.com>
This commit is contained in:
committed by
André Hartmann
parent
02825b5894
commit
9654df9f1f
@@ -53,6 +53,8 @@ void GitSubmitEditorPanelData::clear()
|
||||
author.clear();
|
||||
email.clear();
|
||||
bypassHooks = false;
|
||||
pushAction = CommitOnly;
|
||||
hasRemotes = false;
|
||||
}
|
||||
|
||||
QString GitSubmitEditorPanelData::authorString() const
|
||||
@@ -72,7 +74,8 @@ QString GitSubmitEditorPanelData::authorString() const
|
||||
QDebug operator<<(QDebug d, const GitSubmitEditorPanelData &data)
|
||||
{
|
||||
d.nospace() << " author:" << data.author << " email: " << data.email
|
||||
<< " bypass hooks: " << data.bypassHooks;
|
||||
<< " bypass hooks: " << data.bypassHooks
|
||||
<< " action after commit " << data.pushAction;
|
||||
return d;
|
||||
}
|
||||
|
||||
|
||||
@@ -52,6 +52,12 @@ struct GitSubmitEditorPanelInfo
|
||||
|
||||
QDebug operator<<(QDebug d, const GitSubmitEditorPanelInfo &);
|
||||
|
||||
enum PushAction {
|
||||
CommitOnly,
|
||||
CommitAndPush,
|
||||
CommitAndPushToGerrit
|
||||
};
|
||||
|
||||
struct GitSubmitEditorPanelData
|
||||
{
|
||||
void clear();
|
||||
@@ -61,6 +67,8 @@ struct GitSubmitEditorPanelData
|
||||
QString author;
|
||||
QString email;
|
||||
bool bypassHooks;
|
||||
PushAction pushAction;
|
||||
bool hasRemotes;
|
||||
};
|
||||
|
||||
QDebug operator<<(QDebug d, const GitSubmitEditorPanelData &);
|
||||
|
||||
@@ -308,10 +308,8 @@ void GerritPlugin::addToLocator(Locator::CommandLocator *locator)
|
||||
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
|
||||
GerritPushDialog dialog(topLevel, m_reviewers, ICore::mainWindow());
|
||||
|
||||
@@ -387,6 +385,11 @@ void GerritPlugin::openView()
|
||||
m_dialog.data()->raise();
|
||||
}
|
||||
|
||||
void GerritPlugin::push()
|
||||
{
|
||||
push(Git::Internal::GitPlugin::instance()->currentState().topLevel());
|
||||
}
|
||||
|
||||
QString GerritPlugin::gitBinary()
|
||||
{
|
||||
bool ok;
|
||||
|
||||
@@ -67,6 +67,7 @@ public:
|
||||
static QString gitBinary();
|
||||
static QString branch(const QString &repository);
|
||||
void addToLocator(Locator::CommandLocator *locator);
|
||||
void push(const QString &topLevel);
|
||||
|
||||
public slots:
|
||||
void fetchDisplay(const QSharedPointer<Gerrit::Internal::GerritChange> &change);
|
||||
|
||||
@@ -3044,6 +3044,8 @@ bool GitClient::getCommitData(const QString &workingDirectory,
|
||||
case FixupCommit:
|
||||
break;
|
||||
}
|
||||
|
||||
commitData.panelData.hasRemotes = !synchronousRemotesList(repoDirectory).isEmpty();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -1121,6 +1121,14 @@ bool GitPlugin::submitEditorAboutToClose()
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -1445,6 +1453,11 @@ void GitPlugin::updateContinueAndAbortCommands()
|
||||
}
|
||||
}
|
||||
|
||||
void GitPlugin::delayedPushToGerrit()
|
||||
{
|
||||
m_gerritPlugin->push(m_submitRepository);
|
||||
}
|
||||
|
||||
void GitPlugin::updateBranches(const QString &repository)
|
||||
{
|
||||
if (m_branchDialog && m_branchDialog->isVisible())
|
||||
|
||||
@@ -146,6 +146,7 @@ private slots:
|
||||
void startMergeTool();
|
||||
void continueOrAbortCommand();
|
||||
void updateContinueAndAbortCommands();
|
||||
void delayedPushToGerrit();
|
||||
|
||||
#ifdef WITH_TESTS
|
||||
void testStatusParsing_data();
|
||||
|
||||
@@ -39,6 +39,7 @@
|
||||
#include <QGroupBox>
|
||||
#include <QRegExp>
|
||||
#include <QVBoxLayout>
|
||||
#include <QMenu>
|
||||
|
||||
namespace Git {
|
||||
namespace Internal {
|
||||
@@ -46,6 +47,7 @@ namespace Internal {
|
||||
// ------------------
|
||||
GitSubmitEditorWidget::GitSubmitEditorWidget(QWidget *parent) :
|
||||
VcsBase::SubmitEditorWidget(parent),
|
||||
m_pushAction(CommitOnly),
|
||||
m_gitSubmitPanel(new QWidget),
|
||||
m_logChangeWidget(0),
|
||||
m_hasUnmerged(false),
|
||||
@@ -105,6 +107,14 @@ void GitSubmitEditorWidget::initialize(CommitType commitType,
|
||||
insertTopWidget(m_gitSubmitPanel);
|
||||
setPanelData(data);
|
||||
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)
|
||||
@@ -119,6 +129,7 @@ GitSubmitEditorPanelData GitSubmitEditorWidget::panelData() const
|
||||
rc.author = m_gitSubmitPanelUi.authorLineEdit->text();
|
||||
rc.email = m_gitSubmitPanelUi.emailLineEdit->text();
|
||||
rc.bypassHooks = m_gitSubmitPanelUi.bypassHooksCheckBox->isChecked();
|
||||
rc.pushAction = m_pushAction;
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -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()
|
||||
{
|
||||
bool bothEmpty = m_gitSubmitPanelUi.authorLineEdit->text().isEmpty() &&
|
||||
@@ -171,6 +192,24 @@ void GitSubmitEditorWidget::authorInformationChanged()
|
||||
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
|
||||
{
|
||||
int pos = m_gitSubmitPanelUi.emailLineEdit->cursorPosition();
|
||||
|
||||
@@ -32,6 +32,7 @@
|
||||
|
||||
#include "ui_gitsubmitpanel.h"
|
||||
#include "gitsettings.h"
|
||||
#include "commitdata.h"
|
||||
|
||||
#include <texteditor/syntaxhighlighter.h>
|
||||
#include <vcsbase/submiteditorwidget.h>
|
||||
@@ -77,18 +78,23 @@ public:
|
||||
protected:
|
||||
bool canSubmit() const;
|
||||
QString cleanupDescription(const QString &) const;
|
||||
QString commitName() const;
|
||||
|
||||
signals:
|
||||
void show(const QString &commit);
|
||||
|
||||
private slots:
|
||||
void authorInformationChanged();
|
||||
void commitOnlySlot();
|
||||
void commitAndPushSlot();
|
||||
void commitAndPushToGerritSlot();
|
||||
|
||||
private:
|
||||
bool emailIsValid() const;
|
||||
void setPanelData(const GitSubmitEditorPanelData &data);
|
||||
void setPanelInfo(const GitSubmitEditorPanelInfo &info);
|
||||
|
||||
PushAction m_pushAction;
|
||||
QWidget *m_gitSubmitPanel;
|
||||
LogChangeWidget *m_logChangeWidget;
|
||||
Ui::GitSubmitPanel m_gitSubmitPanelUi;
|
||||
|
||||
Reference in New Issue
Block a user