forked from qt-creator/qt-creator
Git: Allow push after fixup
Direct push after fixup is really useful, especially on gerrit, because it allows easy fixing and direct pushing commits under HEAD. Change-Id: I83980e451c9ae86ac1ac0a55170d6d4141f27d49 Reviewed-by: Orgad Shaneh <orgads@gmail.com>
This commit is contained in:
@@ -38,6 +38,7 @@
|
||||
#include "mergetool.h"
|
||||
#include "branchadddialog.h"
|
||||
|
||||
#include <gerrit/gerritplugin.h>
|
||||
#include <vcsbase/submitfilemodel.h>
|
||||
|
||||
#include <coreplugin/editormanager/editormanager.h>
|
||||
@@ -2526,12 +2527,13 @@ QProcessEnvironment GitClient::processEnvironment() const
|
||||
return environment;
|
||||
}
|
||||
|
||||
bool GitClient::beginStashScope(const QString &workingDirectory, const QString &command, StashFlag flag)
|
||||
bool GitClient::beginStashScope(const QString &workingDirectory, const QString &command,
|
||||
StashFlag flag, PushAction pushAction)
|
||||
{
|
||||
const QString repoDirectory = findRepositoryForDirectory(workingDirectory);
|
||||
QTC_ASSERT(!repoDirectory.isEmpty(), return false);
|
||||
StashInfo &stashInfo = m_stashInfo[repoDirectory];
|
||||
return stashInfo.init(repoDirectory, command, flag);
|
||||
return stashInfo.init(repoDirectory, command, flag, pushAction);
|
||||
}
|
||||
|
||||
GitClient::StashInfo &GitClient::stashInfo(const QString &workingDirectory)
|
||||
@@ -3807,15 +3809,17 @@ unsigned GitClient::synchronousGitVersion(QString *errorMessage) const
|
||||
}
|
||||
|
||||
GitClient::StashInfo::StashInfo() :
|
||||
m_client(GitPlugin::instance()->gitClient())
|
||||
m_client(GitPlugin::instance()->gitClient()),
|
||||
m_pushAction(NoPush)
|
||||
{
|
||||
}
|
||||
|
||||
bool GitClient::StashInfo::init(const QString &workingDirectory, const QString &command,
|
||||
StashFlag flag)
|
||||
StashFlag flag, PushAction pushAction)
|
||||
{
|
||||
m_workingDir = workingDirectory;
|
||||
m_flags = flag;
|
||||
m_pushAction = pushAction;
|
||||
QString errorMessage;
|
||||
QString statusOutput;
|
||||
switch (m_client->gitStatus(m_workingDir, StatusMode(NoUntracked | NoSubmodules),
|
||||
@@ -3914,6 +3918,13 @@ void GitClient::StashInfo::end()
|
||||
if (m_client->stashNameFromMessage(m_workingDir, m_message, &stashName))
|
||||
m_client->stashPop(m_workingDir, stashName);
|
||||
}
|
||||
|
||||
if (m_pushAction == NormalPush)
|
||||
m_client->push(m_workingDir);
|
||||
else if (m_pushAction == PushToGerrit)
|
||||
GitPlugin::instance()->gerritPlugin()->push(m_workingDir);
|
||||
|
||||
m_pushAction = NoPush;
|
||||
m_stashResult = NotStashed;
|
||||
}
|
||||
} // namespace Internal
|
||||
|
||||
@@ -31,6 +31,7 @@
|
||||
#define GITCLIENT_H
|
||||
|
||||
#include "gitsettings.h"
|
||||
#include "commitdata.h"
|
||||
|
||||
#include <coreplugin/editormanager/ieditor.h>
|
||||
|
||||
@@ -110,7 +111,8 @@ public:
|
||||
enum StashResult { StashUnchanged, StashCanceled, StashFailed,
|
||||
Stashed, NotStashed /* User did not want it */ };
|
||||
|
||||
bool init(const QString &workingDirectory, const QString &command, StashFlag flag = Default);
|
||||
bool init(const QString &workingDirectory, const QString &command,
|
||||
StashFlag flag = Default, PushAction pushAction = NoPush);
|
||||
bool stashingFailed() const;
|
||||
void end();
|
||||
StashResult result() const { return m_stashResult; }
|
||||
@@ -125,6 +127,7 @@ public:
|
||||
QString m_workingDir;
|
||||
GitClient *m_client;
|
||||
StashFlag m_flags;
|
||||
PushAction m_pushAction;
|
||||
};
|
||||
|
||||
static const char *stashNamePrefix;
|
||||
@@ -322,7 +325,8 @@ public:
|
||||
|
||||
QProcessEnvironment processEnvironment() const;
|
||||
|
||||
bool beginStashScope(const QString &workingDirectory, const QString &command, StashFlag flag = Default);
|
||||
bool beginStashScope(const QString &workingDirectory, const QString &command,
|
||||
StashFlag flag = Default, PushAction pushAction = NoPush);
|
||||
StashInfo &stashInfo(const QString &workingDirectory);
|
||||
void endStashScope(const QString &workingDirectory);
|
||||
bool isValidRevision(const QString &revision) const;
|
||||
|
||||
@@ -1132,8 +1132,10 @@ bool GitPlugin::submitEditorAboutToClose()
|
||||
return false;
|
||||
cleanCommitMessageFile();
|
||||
if (commitType == FixupCommit) {
|
||||
if (!m_gitClient->beginStashScope(m_submitRepository, QLatin1String("Rebase-fixup"), NoPrompt))
|
||||
if (!m_gitClient->beginStashScope(m_submitRepository, QLatin1String("Rebase-fixup"),
|
||||
NoPrompt, editor->panelData().pushAction)) {
|
||||
return false;
|
||||
}
|
||||
m_gitClient->interactiveRebase(m_submitRepository, amendSHA1, true);
|
||||
} else {
|
||||
m_gitClient->continueCommandIfNeeded(m_submitRepository);
|
||||
@@ -1506,6 +1508,11 @@ GitClient *GitPlugin::gitClient() const
|
||||
return m_gitClient;
|
||||
}
|
||||
|
||||
Gerrit::Internal::GerritPlugin *GitPlugin::gerritPlugin() const
|
||||
{
|
||||
return m_gerritPlugin;
|
||||
}
|
||||
|
||||
#ifdef WITH_TESTS
|
||||
|
||||
#include <QTest>
|
||||
|
||||
@@ -99,6 +99,7 @@ public:
|
||||
void setSettings(const GitSettings &s);
|
||||
|
||||
GitClient *gitClient() const;
|
||||
Gerrit::Internal::GerritPlugin *gerritPlugin() const;
|
||||
|
||||
public slots:
|
||||
void startCommit();
|
||||
|
||||
@@ -109,7 +109,7 @@ void GitSubmitEditorWidget::initialize(CommitType commitType,
|
||||
setPanelData(data);
|
||||
setPanelInfo(info);
|
||||
|
||||
if (enablePush && commitType != FixupCommit) {
|
||||
if (enablePush) {
|
||||
QMenu *menu = new QMenu(this);
|
||||
menu->addAction(tr("&Commit only"), this, SLOT(commitOnlySlot()));
|
||||
menu->addAction(tr("Commit and &Push"), this, SLOT(commitAndPushSlot()));
|
||||
|
||||
Reference in New Issue
Block a user