From e3918b563f87db838ca279ad63a460d992fc03b4 Mon Sep 17 00:00:00 2001 From: Nikita Baryshnikov Date: Thu, 22 Feb 2018 18:31:14 +0300 Subject: [PATCH] Git: show commit given as command line parameter in diff editor MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ex: qtcreator -client -git-show d3eb585db9 from qt-creator source dir. Change-Id: Ice62f062d431d2ab74e3d6832dfc8b0b555dfa19 Reviewed-by: Leena Miettinen Reviewed-by: Orgad Shaneh Reviewed-by: André Hartmann --- src/plugins/git/Git.json.in | 7 +++++++ src/plugins/git/gitplugin.cpp | 18 +++++++++++++++++- src/plugins/git/gitplugin.h | 3 +++ 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/plugins/git/Git.json.in b/src/plugins/git/Git.json.in index 6c129f9b4ab..244ed2f8435 100644 --- a/src/plugins/git/Git.json.in +++ b/src/plugins/git/Git.json.in @@ -15,6 +15,13 @@ \"Category\" : \"Version Control\", \"Description\" : \"Git integration.\", \"Url\" : \"http://www.qt.io\", + \"Arguments\" : [ + { + \"Name\" : \"-git-show\", + \"Parameter\" : \"git commit hash\", + \"Description\" : \"Show given commit hash\" + } + ], $$dependencyList, \"Mimetypes\" : [ diff --git a/src/plugins/git/gitplugin.cpp b/src/plugins/git/gitplugin.cpp index ddab8cd2fed..4657b68ac24 100644 --- a/src/plugins/git/gitplugin.cpp +++ b/src/plugins/git/gitplugin.cpp @@ -289,7 +289,6 @@ QAction *GitPlugin::createRepositoryAction(ActionContainer *ac, const QString &t bool GitPlugin::initialize(const QStringList &arguments, QString *errorMessage) { - Q_UNUSED(arguments) Q_UNUSED(errorMessage) Context context(Constants::GIT_CONTEXT); @@ -668,6 +667,12 @@ bool GitPlugin::initialize(const QStringList &arguments, QString *errorMessage) m_gerritPlugin->updateActions(currentState()); m_gerritPlugin->addToLocator(m_commandLocator); + auto cmdContext = new QObject(this); + connect(Core::ICore::instance(), &Core::ICore::coreOpened, cmdContext, [this, cmdContext, arguments] { + remoteCommand(arguments, QDir::currentPath(), {}); + cmdContext->deleteLater(); + }); + return ok; } @@ -1418,6 +1423,17 @@ void GitPlugin::updateBranches(const QString &repository) m_branchDialog->refreshIfSame(repository); } +QObject *GitPlugin::remoteCommand(const QStringList &options, const QString &workingDirectory, + const QStringList &) +{ + if (!m_gitClient || options.size() < 2) + return nullptr; + + if (options.first() == "-git-show") + m_gitClient->show(workingDirectory, options.at(1)); + return nullptr; +} + void GitPlugin::updateRepositoryBrowserAction() { const bool repositoryEnabled = currentState().hasTopLevel(); diff --git a/src/plugins/git/gitplugin.h b/src/plugins/git/gitplugin.h index aa157c4c87b..f382e3a0abc 100644 --- a/src/plugins/git/gitplugin.h +++ b/src/plugins/git/gitplugin.h @@ -89,6 +89,9 @@ public: void startCommit(CommitType commitType = SimpleCommit); void updateBranches(const QString &repository); + QObject *remoteCommand(const QStringList &options, const QString &workingDirectory, + const QStringList &args) override; + protected: void updateActions(VcsBase::VcsBasePlugin::ActionState) override; bool submitEditorAboutToClose() override;